This shows you the differences between two versions of the page.
Last revision Both sides next revision | |||
source_code_routing_index_generator_cs_100325.zip [2015/08/20 03:08] 127.0.0.1 external edit |
source_code_routing_index_generator_cs_100325.zip [2015/09/09 03:33] admin |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Source_Code_Routing_Index_Generator_CS_100325.zip ====== | + | ====== Source Code Routing Index Generator CS 100325.zip ====== |
- | <noinclude>{{article rating}}</noinclude> | ||
====RoutingIndexGenerator.cs==== | ====RoutingIndexGenerator.cs==== | ||
- | ^ Code ^ | + | |
- | | <source lang="csharp" line="1"> \\ \\ using System; \\ using System.Collections.ObjectModel; \\ using System.IO; \\ using System.Linq; \\ using System.Threading.Tasks; \\ using System.Windows.Forms; \\ using RoutingIndexGenerator.Properties; \\ using ThinkGeo.MapSuite.Core; \\ using ThinkGeo.MapSuite.Routing; \\ \\ namespace RoutingIndexGenerator \\ { \\ public partial class RoutingIndexGenerator : Form \\ { \\ private bool isBuildingRtgFile; \\ private RoutingIndexFileBuilder builder; \\ private BuildRoutingIndexParameters buildRoutingIndexParameters; \\ \\ public RoutingIndexGenerator() \\ { \\ InitializeComponent(); \\ \\ <nowiki>//</nowiki>initialization parameters. \\ buildRoutingIndexParameters = new BuildRoutingIndexParameters(); \\ \\ <nowiki>//</nowiki>read the options for parameter and refresh the Uis \\ cmbGeographyUnit.SelectedIndex = (int)buildRoutingIndexParameters.GeographyUnit; \\ cmbDistanceUnit.SelectedIndex = (int)buildRoutingIndexParameters.DistanceUnit; \\ cmbRouteIndexType.SelectedIndex = (int)buildRoutingIndexParameters.RouteIndexType; \\ cmbSpeedUnit.SelectedIndex = (int)buildRoutingIndexParameters.SpeedOption.SpeedUnit; \\ } \\ \\ private void btnGenerate_Click(object sender, EventArgs e) \\ { \\ isBuildingRtgFile = true; \\ btnGenerate.Enabled = buildRoutingIndexParameters.CheckCanBuildIndexFile() && !isBuildingRtgFile; \\ \\ <nowiki>//</nowiki>display the ProgressBar. \\ pnlProgress.Visible = true; \\ \\ <nowiki>//</nowiki>create a new RoutingIndexFileBuilder. \\ builder = new RoutingIndexFileBuilder(buildRoutingIndexParameters); \\ \\ <nowiki>//</nowiki>Add a event to display refresh the ProgressBar. \\ builder.BuildingRouteSegment += new EventHandler<EventArgs>(builder_BuildingRouteSegment); \\ \\ <nowiki>//</nowiki>Start build index file(.rtg). \\ Task.Factory.StartNew(() => \\ { \\ builder.StartBuildingRtgFile(); \\ }); \\ } \\ \\ private void builder_BuildingRouteSegment(object sender, EventArgs e) \\ { \\ this.BeginInvoke(new Action(() => \\ { \\ <nowiki>//</nowiki>refresh the progress and display the total record count. \\ lblSegmentCount.Text = builder.TotalRecordCount.ToString(); \\ pgbBuildProgress.Value = builder.ProcessedRecordCount * 100 / builder.TotalRecordCount; \\ \\ if (pgbBuildProgress.Value == 100) \\ { \\ isBuildingRtgFile = false; \\ btnGenerate.Enabled = buildRoutingIndexParameters.CheckCanBuildIndexFile() && !isBuildingRtgFile; \\ MessageBox.Show(this, Resources.FinishBuildIndexFile, "Completed"); \\ } \\ })); \\ } \\ \\ private void btnBrowseShapeFile_Click(object sender, EventArgs e) \\ { \\ <nowiki>//</nowiki>create dialog to select the shape file. \\ OpenFileDialog fileDialog = new OpenFileDialog(); \\ fileDialog.Multiselect = false; \\ fileDialog.Filter = Resources.ShapeFileFilterString; \\ \\ if (fileDialog.ShowDialog() == DialogResult.OK) \\ { \\ CheckFileIsRequirement(fileDialog.FileName); \\ \\ txtShapeFilePath.Text = buildRoutingIndexParameters.ShapefilePathName; \\ txtIndexFilePath.Text = buildRoutingIndexParameters.RtgFilePathName; \\ } \\ \\ <nowiki>//</nowiki>check can build index file. \\ btnGenerate.Enabled = buildRoutingIndexParameters.CheckCanBuildIndexFile() && !isBuildingRtgFile; \\ } \\ \\ private void btnSaveRtgFile_Click(object sender, EventArgs e) \\ { \\ <nowiki>//</nowiki>create dialog to save the .rtg file. \\ SaveFileDialog saveFileDialog = new SaveFileDialog(); \\ saveFileDialog.FileName = buildRoutingIndexParameters.RtgFilePathName; \\ saveFileDialog.Filter = Resources.RoutingIndexFileFilterString; \\ saveFileDialog.DefaultExt = ".rtg"; \\ if (saveFileDialog.ShowDialog() == DialogResult.OK) \\ { \\ txtIndexFilePath.Text = saveFileDialog.FileName; \\ } \\ \\ btnGenerate.Enabled = buildRoutingIndexParameters.CheckCanBuildIndexFile() && !isBuildingRtgFile; \\ } \\ \\ private void txtIndexFilePath_TextChanged(object sender, EventArgs e) \\ { \\ buildRoutingIndexParameters.RtgFilePathName = txtIndexFilePath.Text; \\ txtIndexFilePath.Text = buildRoutingIndexParameters.RtgFilePathName; \\ \\ btnGenerate.Enabled = buildRoutingIndexParameters.CheckCanBuildIndexFile() && !isBuildingRtgFile; \\ } \\ \\ private void txtDefaultSpeed_TextChanged(object sender, EventArgs e) \\ { \\ float speed = buildRoutingIndexParameters.SpeedOption.DefaultSpeed; \\ buildRoutingIndexParameters.SpeedOption.DefaultSpeed = float.TryParse(txtDefaultSpeed.Text, out speed) ? speed : 0; \\ \\ btnGenerate.Enabled = buildRoutingIndexParameters.CheckCanBuildIndexFile() && !isBuildingRtgFile; \\ } \\ \\ private void chkSkipOnewayOptions_CheckedChanged(object sender, EventArgs e) \\ { \\ buildRoutingIndexParameters.SkipOnewayOptions = chkSkipOnewayOptions.Checked; \\ pnlOnewayOptions.Enabled = !chkSkipOnewayOptions.Checked; \\ \\ btnGenerate.Enabled = buildRoutingIndexParameters.CheckCanBuildIndexFile() && !isBuildingRtgFile; \\ } \\ \\ private void chkRebuildRtgFile_CheckedChanged(object sender, EventArgs e) \\ { \\ buildRoutingIndexParameters.BuildRoutingDataMode = chkRebuildRtgFile.Checked ? BuildRoutingDataMode.Rebuild : BuildRoutingDataMode.DoNotRebuild; \\ } \\ \\ private void RouteOptionComboBox_SelectedIndexChanged(object sender, EventArgs e) \\ { \\ buildRoutingIndexParameters.GeographyUnit = cmbGeographyUnit.SelectedIndex != -1 ? (GeographyUnit)cmbGeographyUnit.SelectedIndex \\ : buildRoutingIndexParameters.GeographyUnit; \\ \\ buildRoutingIndexParameters.DistanceUnit = cmbDistanceUnit.SelectedIndex != -1 ? (DistanceUnit)cmbDistanceUnit.SelectedIndex \\ : buildRoutingIndexParameters.DistanceUnit; \\ \\ buildRoutingIndexParameters.RouteIndexType = cmbRouteIndexType.SelectedIndex != -1 ? (RouteIndexType)cmbRouteIndexType.SelectedIndex \\ : buildRoutingIndexParameters.RouteIndexType; \\ \\ buildRoutingIndexParameters.SpeedOption.SpeedUnit = cmbSpeedUnit.SelectedIndex != -1 ? (SpeedUnit)cmbSpeedUnit.SelectedIndex \\ : buildRoutingIndexParameters.SpeedOption.SpeedUnit; \\ } \\ \\ private void chkRouteSpeedOptions_CheckedChanged(object sender, EventArgs e) \\ { \\ if (!chkRouteSpeedOptions.Checked) \\ { \\ buildRoutingIndexParameters.SpeedOption.SpeedType = SpeedType.DefaultSpeed; \\ } \\ else \\ { \\ buildRoutingIndexParameters.SpeedOption.SpeedType = rbtnClassSpeed.Checked ? SpeedType.RoadClass : SpeedType.RoadSpeed; \\ } \\ \\ pnlRouteSpeedOptions.Enabled = chkRouteSpeedOptions.Checked; \\ btnGenerate.Enabled = buildRoutingIndexParameters.CheckCanBuildIndexFile() && !isBuildingRtgFile; \\ } \\ \\ private void ShapeFileColumnComboBox_SelectedValueChanged(object sender, EventArgs e) \\ { \\ buildRoutingIndexParameters.OneWayRoadOption.IndicatorColumnName = cmbOnewayIndicatorColumn.Text; \\ buildRoutingIndexParameters.OneWayRoadOption.OneWayColumnName = cmbOnewayRoadColumn.Text; \\ buildRoutingIndexParameters.SpeedOption.SpeedColumnName = cmbSpeedColumn.Text; \\ buildRoutingIndexParameters.SpeedOption.RoadClassColumnName = cmbRoadClassColumn.Text; \\ \\ if (sender.Equals(cmbRoadClassColumn)) \\ { \\ colRoadClass.Items.Clear(); \\ dgvRoadClassSpeed.Rows.Clear(); \\ buildRoutingIndexParameters.SpeedOption.RoadSpeeds.Clear(); \\ \\ ShapeFileFeatureSource source = new ShapeFileFeatureSource(buildRoutingIndexParameters.ShapefilePathName); \\ source.Open(); \\ Collection<Feature> features = source.GetAllFeatures(new string[[]] { cmbRoadClassColumn.Text }); \\ source.Close(); \\ \\ foreach (Feature feature in features) \\ { \\ if (!colRoadClass.Items.Contains(feature.ColumnValues[[cmbRoadClassColumn.Text]])) \\ { \\ colRoadClass.Items.Add(feature.ColumnValues[[cmbRoadClassColumn.Text]]); \\ } \\ } \\ colRoadClass.Items.Remove(string.Empty); \\ } \\ \\ btnGenerate.Enabled = buildRoutingIndexParameters.CheckCanBuildIndexFile() && !isBuildingRtgFile; \\ } \\ \\ private void SpeedTypeRadioButton_CheckedChanged(object sender, EventArgs e) \\ { \\ buildRoutingIndexParameters.SpeedOption.SpeedType = rbtnClassSpeed.Checked ? SpeedType.RoadClass : SpeedType.RoadSpeed; \\ \\ lblSpeedColumn.Enabled = false; \\ cmbSpeedColumn.Enabled = false; \\ lblRoadClassColumn.Enabled = false; \\ cmbRoadClassColumn.Enabled = false; \\ dgvRoadClassSpeed.Enabled = false; \\ \\ if (rbtnClassSpeed.Checked) \\ { \\ lblRoadClassColumn.Enabled = true; \\ cmbRoadClassColumn.Enabled = true; \\ dgvRoadClassSpeed.Enabled = true; \\ } \\ else if (rbtnRoadSpeed.Checked) \\ { \\ lblSpeedColumn.Enabled = true; \\ cmbSpeedColumn.Enabled = true; \\ } \\ \\ btnGenerate.Enabled = buildRoutingIndexParameters.CheckCanBuildIndexFile() && !isBuildingRtgFile; \\ } \\ \\ private void RouteOptionTextBox_TextChanged(object sender, EventArgs e) \\ { \\ buildRoutingIndexParameters.OneWayRoadOption.BothWayRoadValue = txtBothWayRoadValue.Text; \\ buildRoutingIndexParameters.OneWayRoadOption.FromToValue = txtFromToValue.Text; \\ buildRoutingIndexParameters.OneWayRoadOption.ToFromValue = txtToFromValue.Text; \\ buildRoutingIndexParameters.OneWayRoadOption.ClosedRoad = txtColsedRoad.Text; \\ \\ btnGenerate.Enabled = buildRoutingIndexParameters.CheckCanBuildIndexFile() && !isBuildingRtgFile; \\ } \\ \\ private void dgvRoadClassSpeed_CellEndEdit(object sender, DataGridViewCellEventArgs e) \\ { \\ buildRoutingIndexParameters.SpeedOption.RoadSpeeds.Clear(); \\ \\ foreach (DataGridViewRow row in dgvRoadClassSpeed.Rows) \\ { \\ string value = row.Cells[[1]].Value == null ? string.Empty : row.Cells[[1]].Value.ToString(); \\ string key = row.Cells[[0]].Value == null ? string.Empty : row.Cells[[0]].Value.ToString(); \\ \\ double speed = 0; \\ \\ if (!buildRoutingIndexParameters.SpeedOption.RoadSpeeds.Keys.Contains(key) && double.TryParse(value, out speed) && speed > 0) \\ { \\ buildRoutingIndexParameters.SpeedOption.RoadSpeeds.Add(key, speed); \\ } \\ } \\ \\ btnGenerate.Enabled = buildRoutingIndexParameters.CheckCanBuildIndexFile() && !isBuildingRtgFile; \\ } \\ \\ private void btnCancel_Click(object sender, EventArgs e) \\ { \\ if (builder != null) \\ { \\ builder.CancelBuildingRtgFile(); \\ } \\ this.Close(); \\ } \\ \\ private void CheckFileIsRequirement(string shapeFile) \\ { \\ string errorMessage = string.Empty; \\ try \\ { \\ <nowiki>//</nowiki>read ShapeFileType and ShapeFileColumns from ShapeFile. \\ ShapeFileType fileType; \\ Collection<FeatureSourceColumn> columns = ReadShapeFileTypeAndColumns(shapeFile, out fileType); \\ \\ <nowiki>//</nowiki>check if ShapeFileType is Polyline. \\ if (fileType == ShapeFileType.Polyline) \\ { \\ AddColumnItemsToComboBox(columns); \\ buildRoutingIndexParameters.ShapefilePathName = shapeFile; \\ } \\ else \\ { \\ errorMessage = Resources.ShapeFileTypeError; \\ } \\ } \\ catch \\ { \\ errorMessage = Resources.ShapeFileFormatError; \\ } \\ \\ <nowiki>//</nowiki>Display the ErrorMessage. \\ if (!string.IsNullOrEmpty(errorMessage)) \\ { \\ MessageBox.Show(errorMessage, "Error"); \\ } \\ } \\ \\ private Collection<FeatureSourceColumn> ReadShapeFileTypeAndColumns(string shapeFilePath, out ShapeFileType fileType) \\ { \\ Collection<FeatureSourceColumn> columns; \\ \\ ShapeFileFeatureLayer layer = new ShapeFileFeatureLayer(shapeFilePath); \\ layer.Open(); \\ fileType = layer.GetShapeFileType(); \\ columns = layer.FeatureSource.GetColumns(); \\ layer.Close(); \\ \\ return columns; \\ } \\ \\ private void AddColumnItemsToComboBox(Collection<FeatureSourceColumn> columns) \\ { \\ cmbOnewayIndicatorColumn.Items.Clear(); \\ cmbOnewayRoadColumn.Items.Clear(); \\ cmbRoadClassColumn.Items.Clear(); \\ cmbSpeedColumn.Items.Clear(); \\ \\ foreach (FeatureSourceColumn column in columns) \\ { \\ cmbOnewayIndicatorColumn.Items.Add(column); \\ cmbOnewayRoadColumn.Items.Add(column); \\ cmbRoadClassColumn.Items.Add(column); \\ cmbSpeedColumn.Items.Add(column); \\ } \\ } \\ } \\ } \\ \\ \\ </source> | | + | <code csharp> |
+ | |||
+ | using System; | ||
+ | using System.Collections.ObjectModel; | ||
+ | using System.IO; | ||
+ | using System.Linq; | ||
+ | using System.Threading.Tasks; | ||
+ | using System.Windows.Forms; | ||
+ | using RoutingIndexGenerator.Properties; | ||
+ | using ThinkGeo.MapSuite.Core; | ||
+ | using ThinkGeo.MapSuite.Routing; | ||
+ | |||
+ | namespace RoutingIndexGenerator | ||
+ | { | ||
+ | public partial class RoutingIndexGenerator : Form | ||
+ | { | ||
+ | private bool isBuildingRtgFile; | ||
+ | private RoutingIndexFileBuilder builder; | ||
+ | private BuildRoutingIndexParameters buildRoutingIndexParameters; | ||
+ | |||
+ | public RoutingIndexGenerator() | ||
+ | { | ||
+ | InitializeComponent(); | ||
+ | |||
+ | //initialization parameters. | ||
+ | buildRoutingIndexParameters = new BuildRoutingIndexParameters(); | ||
+ | |||
+ | //read the options for parameter and refresh the Uis | ||
+ | cmbGeographyUnit.SelectedIndex = (int)buildRoutingIndexParameters.GeographyUnit; | ||
+ | cmbDistanceUnit.SelectedIndex = (int)buildRoutingIndexParameters.DistanceUnit; | ||
+ | cmbRouteIndexType.SelectedIndex = (int)buildRoutingIndexParameters.RouteIndexType; | ||
+ | cmbSpeedUnit.SelectedIndex = (int)buildRoutingIndexParameters.SpeedOption.SpeedUnit; | ||
+ | } | ||
+ | |||
+ | private void btnGenerate_Click(object sender, EventArgs e) | ||
+ | { | ||
+ | isBuildingRtgFile = true; | ||
+ | btnGenerate.Enabled = buildRoutingIndexParameters.CheckCanBuildIndexFile() && !isBuildingRtgFile; | ||
+ | |||
+ | //display the ProgressBar. | ||
+ | pnlProgress.Visible = true; | ||
+ | |||
+ | //create a new RoutingIndexFileBuilder. | ||
+ | builder = new RoutingIndexFileBuilder(buildRoutingIndexParameters); | ||
+ | |||
+ | //Add a event to display refresh the ProgressBar. | ||
+ | builder.BuildingRouteSegment += new EventHandler<EventArgs>(builder_BuildingRouteSegment); | ||
+ | |||
+ | //Start build index file(.rtg). | ||
+ | Task.Factory.StartNew(() => | ||
+ | { | ||
+ | builder.StartBuildingRtgFile(); | ||
+ | }); | ||
+ | } | ||
+ | |||
+ | private void builder_BuildingRouteSegment(object sender, EventArgs e) | ||
+ | { | ||
+ | this.BeginInvoke(new Action(() => | ||
+ | { | ||
+ | //refresh the progress and display the total record count. | ||
+ | lblSegmentCount.Text = builder.TotalRecordCount.ToString(); | ||
+ | pgbBuildProgress.Value = builder.ProcessedRecordCount * 100 / builder.TotalRecordCount; | ||
+ | |||
+ | if (pgbBuildProgress.Value == 100) | ||
+ | { | ||
+ | isBuildingRtgFile = false; | ||
+ | btnGenerate.Enabled = buildRoutingIndexParameters.CheckCanBuildIndexFile() && !isBuildingRtgFile; | ||
+ | MessageBox.Show(this, Resources.FinishBuildIndexFile, "Completed"); | ||
+ | } | ||
+ | })); | ||
+ | } | ||
+ | |||
+ | private void btnBrowseShapeFile_Click(object sender, EventArgs e) | ||
+ | { | ||
+ | //create dialog to select the shape file. | ||
+ | OpenFileDialog fileDialog = new OpenFileDialog(); | ||
+ | fileDialog.Multiselect = false; | ||
+ | fileDialog.Filter = Resources.ShapeFileFilterString; | ||
+ | |||
+ | if (fileDialog.ShowDialog() == DialogResult.OK) | ||
+ | { | ||
+ | CheckFileIsRequirement(fileDialog.FileName); | ||
+ | |||
+ | txtShapeFilePath.Text = buildRoutingIndexParameters.ShapefilePathName; | ||
+ | txtIndexFilePath.Text = buildRoutingIndexParameters.RtgFilePathName; | ||
+ | } | ||
+ | |||
+ | //check can build index file. | ||
+ | btnGenerate.Enabled = buildRoutingIndexParameters.CheckCanBuildIndexFile() && !isBuildingRtgFile; | ||
+ | } | ||
+ | |||
+ | private void btnSaveRtgFile_Click(object sender, EventArgs e) | ||
+ | { | ||
+ | //create dialog to save the .rtg file. | ||
+ | SaveFileDialog saveFileDialog = new SaveFileDialog(); | ||
+ | saveFileDialog.FileName = buildRoutingIndexParameters.RtgFilePathName; | ||
+ | saveFileDialog.Filter = Resources.RoutingIndexFileFilterString; | ||
+ | saveFileDialog.DefaultExt = ".rtg"; | ||
+ | if (saveFileDialog.ShowDialog() == DialogResult.OK) | ||
+ | { | ||
+ | txtIndexFilePath.Text = saveFileDialog.FileName; | ||
+ | } | ||
+ | |||
+ | btnGenerate.Enabled = buildRoutingIndexParameters.CheckCanBuildIndexFile() && !isBuildingRtgFile; | ||
+ | } | ||
+ | |||
+ | private void txtIndexFilePath_TextChanged(object sender, EventArgs e) | ||
+ | { | ||
+ | buildRoutingIndexParameters.RtgFilePathName = txtIndexFilePath.Text; | ||
+ | txtIndexFilePath.Text = buildRoutingIndexParameters.RtgFilePathName; | ||
+ | |||
+ | btnGenerate.Enabled = buildRoutingIndexParameters.CheckCanBuildIndexFile() && !isBuildingRtgFile; | ||
+ | } | ||
+ | |||
+ | private void txtDefaultSpeed_TextChanged(object sender, EventArgs e) | ||
+ | { | ||
+ | float speed = buildRoutingIndexParameters.SpeedOption.DefaultSpeed; | ||
+ | buildRoutingIndexParameters.SpeedOption.DefaultSpeed = float.TryParse(txtDefaultSpeed.Text, out speed) ? speed : 0; | ||
+ | |||
+ | btnGenerate.Enabled = buildRoutingIndexParameters.CheckCanBuildIndexFile() && !isBuildingRtgFile; | ||
+ | } | ||
+ | |||
+ | private void chkSkipOnewayOptions_CheckedChanged(object sender, EventArgs e) | ||
+ | { | ||
+ | buildRoutingIndexParameters.SkipOnewayOptions = chkSkipOnewayOptions.Checked; | ||
+ | pnlOnewayOptions.Enabled = !chkSkipOnewayOptions.Checked; | ||
+ | |||
+ | btnGenerate.Enabled = buildRoutingIndexParameters.CheckCanBuildIndexFile() && !isBuildingRtgFile; | ||
+ | } | ||
+ | |||
+ | private void chkRebuildRtgFile_CheckedChanged(object sender, EventArgs e) | ||
+ | { | ||
+ | buildRoutingIndexParameters.BuildRoutingDataMode = chkRebuildRtgFile.Checked ? BuildRoutingDataMode.Rebuild : BuildRoutingDataMode.DoNotRebuild; | ||
+ | } | ||
+ | |||
+ | private void RouteOptionComboBox_SelectedIndexChanged(object sender, EventArgs e) | ||
+ | { | ||
+ | buildRoutingIndexParameters.GeographyUnit = cmbGeographyUnit.SelectedIndex != -1 ? (GeographyUnit)cmbGeographyUnit.SelectedIndex | ||
+ | : buildRoutingIndexParameters.GeographyUnit; | ||
+ | |||
+ | buildRoutingIndexParameters.DistanceUnit = cmbDistanceUnit.SelectedIndex != -1 ? (DistanceUnit)cmbDistanceUnit.SelectedIndex | ||
+ | : buildRoutingIndexParameters.DistanceUnit; | ||
+ | |||
+ | buildRoutingIndexParameters.RouteIndexType = cmbRouteIndexType.SelectedIndex != -1 ? (RouteIndexType)cmbRouteIndexType.SelectedIndex | ||
+ | : buildRoutingIndexParameters.RouteIndexType; | ||
+ | |||
+ | buildRoutingIndexParameters.SpeedOption.SpeedUnit = cmbSpeedUnit.SelectedIndex != -1 ? (SpeedUnit)cmbSpeedUnit.SelectedIndex | ||
+ | : buildRoutingIndexParameters.SpeedOption.SpeedUnit; | ||
+ | } | ||
+ | |||
+ | private void chkRouteSpeedOptions_CheckedChanged(object sender, EventArgs e) | ||
+ | { | ||
+ | if (!chkRouteSpeedOptions.Checked) | ||
+ | { | ||
+ | buildRoutingIndexParameters.SpeedOption.SpeedType = SpeedType.DefaultSpeed; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | buildRoutingIndexParameters.SpeedOption.SpeedType = rbtnClassSpeed.Checked ? SpeedType.RoadClass : SpeedType.RoadSpeed; | ||
+ | } | ||
+ | |||
+ | pnlRouteSpeedOptions.Enabled = chkRouteSpeedOptions.Checked; | ||
+ | btnGenerate.Enabled = buildRoutingIndexParameters.CheckCanBuildIndexFile() && !isBuildingRtgFile; | ||
+ | } | ||
+ | |||
+ | private void ShapeFileColumnComboBox_SelectedValueChanged(object sender, EventArgs e) | ||
+ | { | ||
+ | buildRoutingIndexParameters.OneWayRoadOption.IndicatorColumnName = cmbOnewayIndicatorColumn.Text; | ||
+ | buildRoutingIndexParameters.OneWayRoadOption.OneWayColumnName = cmbOnewayRoadColumn.Text; | ||
+ | buildRoutingIndexParameters.SpeedOption.SpeedColumnName = cmbSpeedColumn.Text; | ||
+ | buildRoutingIndexParameters.SpeedOption.RoadClassColumnName = cmbRoadClassColumn.Text; | ||
+ | |||
+ | if (sender.Equals(cmbRoadClassColumn)) | ||
+ | { | ||
+ | colRoadClass.Items.Clear(); | ||
+ | dgvRoadClassSpeed.Rows.Clear(); | ||
+ | buildRoutingIndexParameters.SpeedOption.RoadSpeeds.Clear(); | ||
+ | |||
+ | ShapeFileFeatureSource source = new ShapeFileFeatureSource(buildRoutingIndexParameters.ShapefilePathName); | ||
+ | source.Open(); | ||
+ | Collection<Feature> features = source.GetAllFeatures(new string[] { cmbRoadClassColumn.Text }); | ||
+ | source.Close(); | ||
+ | |||
+ | foreach (Feature feature in features) | ||
+ | { | ||
+ | if (!colRoadClass.Items.Contains(feature.ColumnValues[cmbRoadClassColumn.Text])) | ||
+ | { | ||
+ | colRoadClass.Items.Add(feature.ColumnValues[cmbRoadClassColumn.Text]); | ||
+ | } | ||
+ | } | ||
+ | colRoadClass.Items.Remove(string.Empty); | ||
+ | } | ||
+ | |||
+ | btnGenerate.Enabled = buildRoutingIndexParameters.CheckCanBuildIndexFile() && !isBuildingRtgFile; | ||
+ | } | ||
+ | |||
+ | private void SpeedTypeRadioButton_CheckedChanged(object sender, EventArgs e) | ||
+ | { | ||
+ | buildRoutingIndexParameters.SpeedOption.SpeedType = rbtnClassSpeed.Checked ? SpeedType.RoadClass : SpeedType.RoadSpeed; | ||
+ | |||
+ | lblSpeedColumn.Enabled = false; | ||
+ | cmbSpeedColumn.Enabled = false; | ||
+ | lblRoadClassColumn.Enabled = false; | ||
+ | cmbRoadClassColumn.Enabled = false; | ||
+ | dgvRoadClassSpeed.Enabled = false; | ||
+ | |||
+ | if (rbtnClassSpeed.Checked) | ||
+ | { | ||
+ | lblRoadClassColumn.Enabled = true; | ||
+ | cmbRoadClassColumn.Enabled = true; | ||
+ | dgvRoadClassSpeed.Enabled = true; | ||
+ | } | ||
+ | else if (rbtnRoadSpeed.Checked) | ||
+ | { | ||
+ | lblSpeedColumn.Enabled = true; | ||
+ | cmbSpeedColumn.Enabled = true; | ||
+ | } | ||
+ | |||
+ | btnGenerate.Enabled = buildRoutingIndexParameters.CheckCanBuildIndexFile() && !isBuildingRtgFile; | ||
+ | } | ||
+ | |||
+ | private void RouteOptionTextBox_TextChanged(object sender, EventArgs e) | ||
+ | { | ||
+ | buildRoutingIndexParameters.OneWayRoadOption.BothWayRoadValue = txtBothWayRoadValue.Text; | ||
+ | buildRoutingIndexParameters.OneWayRoadOption.FromToValue = txtFromToValue.Text; | ||
+ | buildRoutingIndexParameters.OneWayRoadOption.ToFromValue = txtToFromValue.Text; | ||
+ | buildRoutingIndexParameters.OneWayRoadOption.ClosedRoad = txtColsedRoad.Text; | ||
+ | |||
+ | btnGenerate.Enabled = buildRoutingIndexParameters.CheckCanBuildIndexFile() && !isBuildingRtgFile; | ||
+ | } | ||
+ | |||
+ | private void dgvRoadClassSpeed_CellEndEdit(object sender, DataGridViewCellEventArgs e) | ||
+ | { | ||
+ | buildRoutingIndexParameters.SpeedOption.RoadSpeeds.Clear(); | ||
+ | |||
+ | foreach (DataGridViewRow row in dgvRoadClassSpeed.Rows) | ||
+ | { | ||
+ | string value = row.Cells[1].Value == null ? string.Empty : row.Cells[1].Value.ToString(); | ||
+ | string key = row.Cells[0].Value == null ? string.Empty : row.Cells[0].Value.ToString(); | ||
+ | |||
+ | double speed = 0; | ||
+ | |||
+ | if (!buildRoutingIndexParameters.SpeedOption.RoadSpeeds.Keys.Contains(key) && double.TryParse(value, out speed) && speed > 0) | ||
+ | { | ||
+ | buildRoutingIndexParameters.SpeedOption.RoadSpeeds.Add(key, speed); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | btnGenerate.Enabled = buildRoutingIndexParameters.CheckCanBuildIndexFile() && !isBuildingRtgFile; | ||
+ | } | ||
+ | |||
+ | private void btnCancel_Click(object sender, EventArgs e) | ||
+ | { | ||
+ | if (builder != null) | ||
+ | { | ||
+ | builder.CancelBuildingRtgFile(); | ||
+ | } | ||
+ | this.Close(); | ||
+ | } | ||
+ | |||
+ | private void CheckFileIsRequirement(string shapeFile) | ||
+ | { | ||
+ | string errorMessage = string.Empty; | ||
+ | try | ||
+ | { | ||
+ | //read ShapeFileType and ShapeFileColumns from ShapeFile. | ||
+ | ShapeFileType fileType; | ||
+ | Collection<FeatureSourceColumn> columns = ReadShapeFileTypeAndColumns(shapeFile, out fileType); | ||
+ | |||
+ | //check if ShapeFileType is Polyline. | ||
+ | if (fileType == ShapeFileType.Polyline) | ||
+ | { | ||
+ | AddColumnItemsToComboBox(columns); | ||
+ | buildRoutingIndexParameters.ShapefilePathName = shapeFile; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | errorMessage = Resources.ShapeFileTypeError; | ||
+ | } | ||
+ | } | ||
+ | catch | ||
+ | { | ||
+ | errorMessage = Resources.ShapeFileFormatError; | ||
+ | } | ||
+ | |||
+ | //Display the ErrorMessage. | ||
+ | if (!string.IsNullOrEmpty(errorMessage)) | ||
+ | { | ||
+ | MessageBox.Show(errorMessage, "Error"); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | private Collection<FeatureSourceColumn> ReadShapeFileTypeAndColumns(string shapeFilePath, out ShapeFileType fileType) | ||
+ | { | ||
+ | Collection<FeatureSourceColumn> columns; | ||
+ | |||
+ | ShapeFileFeatureLayer layer = new ShapeFileFeatureLayer(shapeFilePath); | ||
+ | layer.Open(); | ||
+ | fileType = layer.GetShapeFileType(); | ||
+ | columns = layer.FeatureSource.GetColumns(); | ||
+ | layer.Close(); | ||
+ | |||
+ | return columns; | ||
+ | } | ||
+ | |||
+ | private void AddColumnItemsToComboBox(Collection<FeatureSourceColumn> columns) | ||
+ | { | ||
+ | cmbOnewayIndicatorColumn.Items.Clear(); | ||
+ | cmbOnewayRoadColumn.Items.Clear(); | ||
+ | cmbRoadClassColumn.Items.Clear(); | ||
+ | cmbSpeedColumn.Items.Clear(); | ||
+ | |||
+ | foreach (FeatureSourceColumn column in columns) | ||
+ | { | ||
+ | cmbOnewayIndicatorColumn.Items.Add(column); | ||
+ | cmbOnewayRoadColumn.Items.Add(column); | ||
+ | cmbRoadClassColumn.Items.Add(column); | ||
+ | cmbSpeedColumn.Items.Add(column); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | </code> | ||
====RoutingIndexFileBuilder.cs==== | ====RoutingIndexFileBuilder.cs==== | ||
- | ^ Code ^ | + | |
- | | <source lang="csharp" line="1"> \\ \\ using System; \\ using System.Collections.ObjectModel; \\ using System.IO; \\ using RoutingIndexGenerator.Properties; \\ using ThinkGeo.MapSuite.Core; \\ using ThinkGeo.MapSuite.Routing; \\ \\ namespace RoutingIndexGenerator \\ { \\ public class RoutingIndexFileBuilder \\ { \\ public event EventHandler<EventArgs> BuildingRouteSegment; \\ \\ private BuildRoutingIndexParameters buildRtgParameter; \\ private bool cancelBuilding; \\ private ShapeFileFeatureSource routableFeatureSource; \\ \\ private int processedRecordCount; \\ private int totalRecordCount; \\ private Collection<string> requiredColumns; \\ \\ public RoutingIndexFileBuilder() \\ : this(new BuildRoutingIndexParameters()) \\ { } \\ \\ public RoutingIndexFileBuilder(BuildRoutingIndexParameters buildRtgParameter) \\ { \\ this.buildRtgParameter = buildRtgParameter; \\ } \\ \\ public int ProcessedRecordCount \\ { \\ get { return processedRecordCount; } \\ } \\ \\ public int TotalRecordCount \\ { \\ get { return totalRecordCount; } \\ } \\ \\ public BuildRoutingIndexParameters BuildRtgParameter \\ { \\ get { return buildRtgParameter; } \\ } \\ \\ public void StartBuildingRtgFile() \\ { \\ if (!buildRtgParameter.CheckCanBuildIndexFile()) \\ { \\ throw new NotSupportedException(Resources.ParametersNotSuppertBuildingIndex); \\ } \\ \\ processedRecordCount = 0; \\ \\ routableFeatureSource = new ShapeFileFeatureSource(buildRtgParameter.ShapefilePathName); \\ routableFeatureSource.Open(); \\ \\ totalRecordCount = routableFeatureSource.GetCount(); \\ \\ RtgRoutingSource.BuildingRoutingData += RtgRoutingSource_BuildingRoutingData; \\ RtgRoutingSource.GenerateRoutingData(buildRtgParameter.RtgFilePathName, buildRtgParameter.ShapefilePathName, buildRtgParameter.ShapefilePathName, buildRtgParameter.BuildRoutingDataMode, buildRtgParameter.GeographyUnit, buildRtgParameter.DistanceUnit); \\ RtgRoutingSource.BuildingRoutingData -= RtgRoutingSource_BuildingRoutingData; \\ \\ routableFeatureSource.Close(); \\ \\ if (cancelBuilding == true) \\ { \\ File.Delete(Path.ChangeExtension(buildRtgParameter.RtgFilePathName, ".rtg")); \\ File.Delete(Path.ChangeExtension(buildRtgParameter.RtgFilePathName, ".rtx")); \\ } \\ } \\ \\ public void CancelBuildingRtgFile() \\ { \\ cancelBuilding = true; \\ } \\ \\ private void RtgRoutingSource_BuildingRoutingData(object sender, BuildingRoutingDataRtgRoutingSourceEventArgs e) \\ { \\ <nowiki>//</nowiki> Make progressBar move forward a step \\ processedRecordCount++; \\ OnBuildingRouteSegment(); \\ \\ <nowiki>//</nowiki> Get the processing Feature \\ if (requiredColumns == null) \\ { \\ requiredColumns = GetRequiredColumns(); \\ } \\ \\ Feature feature = routableFeatureSource.GetFeatureById(e.RouteSegment.FeatureId, requiredColumns); \\ if (!buildRtgParameter.SkipOnewayOptions) \\ { \\ ProcessOneWayRoad(e, feature, requiredColumns); \\ } \\ \\ if (buildRtgParameter.RouteIndexType == RouteIndexType.Fastest) \\ { \\ if (buildRtgParameter.SpeedOption.SpeedType == SpeedType.RoadClass && !string.IsNullOrEmpty(buildRtgParameter.SpeedOption.RoadClassColumnName)) \\ { \\ string featureRoadClassValue = feature.ColumnValues[[buildRtgParameter.SpeedOption.RoadClassColumnName]]; \\ e.RouteSegment.Weight = e.RouteSegment.Distance / GetSpeed(featureRoadClassValue); \\ } \\ else if (buildRtgParameter.SpeedOption.SpeedType == SpeedType.RoadSpeed && !string.IsNullOrEmpty(buildRtgParameter.SpeedOption.SpeedColumnName)) \\ { \\ float speed = 0; \\ string speedString = feature.ColumnValues[[buildRtgParameter.SpeedOption.SpeedColumnName]]; \\ speed = float.TryParse(speedString, out speed) ? speed : buildRtgParameter.SpeedOption.DefaultSpeed; \\ e.RouteSegment.Weight = e.RouteSegment.Distance / speed; \\ } \\ else \\ { \\ e.RouteSegment.Weight = e.RouteSegment.Distance / buildRtgParameter.SpeedOption.DefaultSpeed; \\ } \\ } \\ \\ e.Cancel = cancelBuilding; \\ } \\ \\ private Collection<string> GetRequiredColumns() \\ { \\ Collection<string> requiredColumns = new Collection<string>(); \\ if (!buildRtgParameter.SkipOnewayOptions) \\ { \\ if (!string.IsNullOrEmpty(buildRtgParameter.OneWayRoadOption.OneWayColumnName)) \\ { \\ requiredColumns.Add(buildRtgParameter.OneWayRoadOption.OneWayColumnName); \\ } \\ if (!string.IsNullOrEmpty(buildRtgParameter.OneWayRoadOption.IndicatorColumnName)) \\ { \\ requiredColumns.Add(buildRtgParameter.OneWayRoadOption.IndicatorColumnName); \\ } \\ } \\ \\ string speedColumn = string.Empty; \\ switch (buildRtgParameter.SpeedOption.SpeedType) \\ { \\ case SpeedType.RoadClass: \\ speedColumn = buildRtgParameter.SpeedOption.RoadClassColumnName; \\ break; \\ case SpeedType.RoadSpeed: \\ speedColumn = buildRtgParameter.SpeedOption.SpeedColumnName; \\ break; \\ default: \\ break; \\ } \\ if (!string.IsNullOrEmpty(speedColumn)) \\ { \\ requiredColumns.Add(speedColumn); \\ } \\ \\ return requiredColumns; \\ } \\ \\ private void ProcessOneWayRoad(BuildingRoutingDataRtgRoutingSourceEventArgs e, Feature roadFeature, Collection<string> oneWayColumns) \\ { \\ LineShape lineShape = GetLineShape(roadFeature); \\ \\ <nowiki>//</nowiki> handled feature is one-way road \\ if (!roadFeature.ColumnValues[[buildRtgParameter.OneWayRoadOption.OneWayColumnName]].Equals(buildRtgParameter.OneWayRoadOption.BothWayRoadValue, StringComparison.InvariantCultureIgnoreCase)) \\ { \\ if (roadFeature.ColumnValues[[buildRtgParameter.OneWayRoadOption.IndicatorColumnName]].Equals(buildRtgParameter.OneWayRoadOption.FromToValue)) \\ { \\ e.RouteSegment.StartPointAdjacentIds.Clear(); \\ } \\ else if (roadFeature.ColumnValues[[buildRtgParameter.OneWayRoadOption.IndicatorColumnName]].Equals(buildRtgParameter.OneWayRoadOption.ToFromValue)) \\ { \\ e.RouteSegment.EndPointAdjacentIds.Clear(); \\ } \\ else if (roadFeature.ColumnValues[[buildRtgParameter.OneWayRoadOption.IndicatorColumnName]].Equals(buildRtgParameter.OneWayRoadOption.ClosedRoad)) \\ { \\ e.RouteSegment.StartPointAdjacentIds.Clear(); \\ e.RouteSegment.EndPointAdjacentIds.Clear(); \\ } \\ } \\ \\ <nowiki>//</nowiki> analysis adjacent one-way road features \\ Collection<string> removedStartPointAdjacentIds = GetRemovedAdjacentIds(e.RouteSegment.StartPointAdjacentIds, new PointShape(lineShape.Vertices[[0]]), oneWayColumns); \\ foreach (string id in removedStartPointAdjacentIds) \\ { \\ e.RouteSegment.StartPointAdjacentIds.Remove(id); \\ } \\ Collection<string> removedEndPointAdjacentIds = GetRemovedAdjacentIds(e.RouteSegment.EndPointAdjacentIds, new PointShape(lineShape.Vertices[[lineShape.Vertices.Count|- 1]]), oneWayColumns); \\ foreach (string id in removedEndPointAdjacentIds) \\ { \\ e.RouteSegment.EndPointAdjacentIds.Remove(id); \\ } \\ } \\ \\ private Collection<string> GetRemovedAdjacentIds(Collection<string> adjacentIds, PointShape intersectingPoint, Collection<string> oneWayColumns) \\ { \\ Collection<string> removedIds = new Collection<string>(); \\ foreach (string id in adjacentIds) \\ { \\ Feature adjacentFeature = routableFeatureSource.GetFeatureById(id, oneWayColumns); \\ if (!adjacentFeature.ColumnValues[[buildRtgParameter.OneWayRoadOption.OneWayColumnName]].Equals(buildRtgParameter.OneWayRoadOption.BothWayRoadValue, StringComparison.InvariantCultureIgnoreCase)) \\ { \\ LineShape adjacentLineShape = GetLineShape(adjacentFeature); \\ double distanceFromAdjacentStartToIntersecting = new PointShape(adjacentLineShape.Vertices[[0]]).GetDistanceTo(intersectingPoint, buildRtgParameter.GeographyUnit, buildRtgParameter.DistanceUnit); \\ double distanceFromAdjacentEndToIntersecting = new PointShape(adjacentLineShape.Vertices[[adjacentLineShape.Vertices.Count|- 1]]).GetDistanceTo(intersectingPoint, buildRtgParameter.GeographyUnit, buildRtgParameter.DistanceUnit); \\ if (distanceFromAdjacentStartToIntersecting <= distanceFromAdjacentEndToIntersecting \\ && adjacentFeature.ColumnValues[[buildRtgParameter.OneWayRoadOption.IndicatorColumnName]].Equals(buildRtgParameter.OneWayRoadOption.ToFromValue)) \\ { \\ removedIds.Add(id); \\ } \\ else if (distanceFromAdjacentEndToIntersecting <= distanceFromAdjacentStartToIntersecting \\ && adjacentFeature.ColumnValues[[buildRtgParameter.OneWayRoadOption.IndicatorColumnName]].Equals(buildRtgParameter.OneWayRoadOption.FromToValue)) \\ { \\ removedIds.Add(id); \\ } \\ else if (adjacentFeature.ColumnValues[[buildRtgParameter.OneWayRoadOption.IndicatorColumnName]].Equals(buildRtgParameter.OneWayRoadOption.ClosedRoad)) \\ { \\ removedIds.Add(id); \\ } \\ } \\ } \\ return removedIds; \\ } \\ \\ private float GetSpeed(String featureRoadSpeedClassValue) \\ { \\ float result = buildRtgParameter.SpeedOption.DefaultSpeed; \\ foreach (var item in buildRtgParameter.SpeedOption.RoadSpeeds) \\ { \\ if (item.Key.Equals(featureRoadSpeedClassValue, StringComparison.OrdinalIgnoreCase)) \\ { \\ result = (float)item.Value; \\ break; \\ } \\ } \\ \\ return result; \\ } \\ \\ private static LineShape GetLineShape(Feature lineFeature) \\ { \\ BaseShape baseShape = lineFeature.GetShape(); \\ \\ LineShape lineShape = baseShape as LineShape; \\ if (lineShape == null) \\ { \\ MultilineShape lineShapes = ((MultilineShape)baseShape); \\ Collection<Vertex> vertices = new Collection<Vertex>(); \\ \\ foreach (LineShape line in lineShapes.Lines) \\ { \\ for (int i = 0; i < line.Vertices.Count; i++) \\ { \\ vertices.Add(line.Vertices[[i]]); \\ } \\ } \\ \\ lineShape = new LineShape(vertices); \\ lineShape.Id = baseShape.Id; \\ lineShape.Tag = baseShape.Tag; \\ } \\ \\ return lineShape; \\ } \\ \\ protected virtual void OnBuildingRouteSegment() \\ { \\ if (BuildingRouteSegment != null) \\ { \\ BuildingRouteSegment(this, new EventArgs()); \\ } \\ } \\ } \\ } \\ \\ \\ </source> | | + | <code csharp> |
+ | |||
+ | using System; | ||
+ | using System.Collections.ObjectModel; | ||
+ | using System.IO; | ||
+ | using RoutingIndexGenerator.Properties; | ||
+ | using ThinkGeo.MapSuite.Core; | ||
+ | using ThinkGeo.MapSuite.Routing; | ||
+ | |||
+ | namespace RoutingIndexGenerator | ||
+ | { | ||
+ | public class RoutingIndexFileBuilder | ||
+ | { | ||
+ | public event EventHandler<EventArgs> BuildingRouteSegment; | ||
+ | |||
+ | private BuildRoutingIndexParameters buildRtgParameter; | ||
+ | private bool cancelBuilding; | ||
+ | private ShapeFileFeatureSource routableFeatureSource; | ||
+ | |||
+ | private int processedRecordCount; | ||
+ | private int totalRecordCount; | ||
+ | private Collection<string> requiredColumns; | ||
+ | |||
+ | public RoutingIndexFileBuilder() | ||
+ | : this(new BuildRoutingIndexParameters()) | ||
+ | { } | ||
+ | |||
+ | public RoutingIndexFileBuilder(BuildRoutingIndexParameters buildRtgParameter) | ||
+ | { | ||
+ | this.buildRtgParameter = buildRtgParameter; | ||
+ | } | ||
+ | |||
+ | public int ProcessedRecordCount | ||
+ | { | ||
+ | get { return processedRecordCount; } | ||
+ | } | ||
+ | |||
+ | public int TotalRecordCount | ||
+ | { | ||
+ | get { return totalRecordCount; } | ||
+ | } | ||
+ | |||
+ | public BuildRoutingIndexParameters BuildRtgParameter | ||
+ | { | ||
+ | get { return buildRtgParameter; } | ||
+ | } | ||
+ | |||
+ | public void StartBuildingRtgFile() | ||
+ | { | ||
+ | if (!buildRtgParameter.CheckCanBuildIndexFile()) | ||
+ | { | ||
+ | throw new NotSupportedException(Resources.ParametersNotSuppertBuildingIndex); | ||
+ | } | ||
+ | |||
+ | processedRecordCount = 0; | ||
+ | |||
+ | routableFeatureSource = new ShapeFileFeatureSource(buildRtgParameter.ShapefilePathName); | ||
+ | routableFeatureSource.Open(); | ||
+ | |||
+ | totalRecordCount = routableFeatureSource.GetCount(); | ||
+ | |||
+ | RtgRoutingSource.BuildingRoutingData += RtgRoutingSource_BuildingRoutingData; | ||
+ | RtgRoutingSource.GenerateRoutingData(buildRtgParameter.RtgFilePathName, buildRtgParameter.ShapefilePathName, buildRtgParameter.ShapefilePathName, buildRtgParameter.BuildRoutingDataMode, buildRtgParameter.GeographyUnit, buildRtgParameter.DistanceUnit); | ||
+ | RtgRoutingSource.BuildingRoutingData -= RtgRoutingSource_BuildingRoutingData; | ||
+ | |||
+ | routableFeatureSource.Close(); | ||
+ | |||
+ | if (cancelBuilding == true) | ||
+ | { | ||
+ | File.Delete(Path.ChangeExtension(buildRtgParameter.RtgFilePathName, ".rtg")); | ||
+ | File.Delete(Path.ChangeExtension(buildRtgParameter.RtgFilePathName, ".rtx")); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | public void CancelBuildingRtgFile() | ||
+ | { | ||
+ | cancelBuilding = true; | ||
+ | } | ||
+ | |||
+ | private void RtgRoutingSource_BuildingRoutingData(object sender, BuildingRoutingDataRtgRoutingSourceEventArgs e) | ||
+ | { | ||
+ | // Make progressBar move forward a step | ||
+ | processedRecordCount++; | ||
+ | OnBuildingRouteSegment(); | ||
+ | |||
+ | // Get the processing Feature | ||
+ | if (requiredColumns == null) | ||
+ | { | ||
+ | requiredColumns = GetRequiredColumns(); | ||
+ | } | ||
+ | |||
+ | Feature feature = routableFeatureSource.GetFeatureById(e.RouteSegment.FeatureId, requiredColumns); | ||
+ | if (!buildRtgParameter.SkipOnewayOptions) | ||
+ | { | ||
+ | ProcessOneWayRoad(e, feature, requiredColumns); | ||
+ | } | ||
+ | |||
+ | if (buildRtgParameter.RouteIndexType == RouteIndexType.Fastest) | ||
+ | { | ||
+ | if (buildRtgParameter.SpeedOption.SpeedType == SpeedType.RoadClass && !string.IsNullOrEmpty(buildRtgParameter.SpeedOption.RoadClassColumnName)) | ||
+ | { | ||
+ | string featureRoadClassValue = feature.ColumnValues[buildRtgParameter.SpeedOption.RoadClassColumnName]; | ||
+ | e.RouteSegment.Weight = e.RouteSegment.Distance / GetSpeed(featureRoadClassValue); | ||
+ | } | ||
+ | else if (buildRtgParameter.SpeedOption.SpeedType == SpeedType.RoadSpeed && !string.IsNullOrEmpty(buildRtgParameter.SpeedOption.SpeedColumnName)) | ||
+ | { | ||
+ | float speed = 0; | ||
+ | string speedString = feature.ColumnValues[buildRtgParameter.SpeedOption.SpeedColumnName]; | ||
+ | speed = float.TryParse(speedString, out speed) ? speed : buildRtgParameter.SpeedOption.DefaultSpeed; | ||
+ | e.RouteSegment.Weight = e.RouteSegment.Distance / speed; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | e.RouteSegment.Weight = e.RouteSegment.Distance / buildRtgParameter.SpeedOption.DefaultSpeed; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | e.Cancel = cancelBuilding; | ||
+ | } | ||
+ | |||
+ | private Collection<string> GetRequiredColumns() | ||
+ | { | ||
+ | Collection<string> requiredColumns = new Collection<string>(); | ||
+ | if (!buildRtgParameter.SkipOnewayOptions) | ||
+ | { | ||
+ | if (!string.IsNullOrEmpty(buildRtgParameter.OneWayRoadOption.OneWayColumnName)) | ||
+ | { | ||
+ | requiredColumns.Add(buildRtgParameter.OneWayRoadOption.OneWayColumnName); | ||
+ | } | ||
+ | if (!string.IsNullOrEmpty(buildRtgParameter.OneWayRoadOption.IndicatorColumnName)) | ||
+ | { | ||
+ | requiredColumns.Add(buildRtgParameter.OneWayRoadOption.IndicatorColumnName); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | string speedColumn = string.Empty; | ||
+ | switch (buildRtgParameter.SpeedOption.SpeedType) | ||
+ | { | ||
+ | case SpeedType.RoadClass: | ||
+ | speedColumn = buildRtgParameter.SpeedOption.RoadClassColumnName; | ||
+ | break; | ||
+ | case SpeedType.RoadSpeed: | ||
+ | speedColumn = buildRtgParameter.SpeedOption.SpeedColumnName; | ||
+ | break; | ||
+ | default: | ||
+ | break; | ||
+ | } | ||
+ | if (!string.IsNullOrEmpty(speedColumn)) | ||
+ | { | ||
+ | requiredColumns.Add(speedColumn); | ||
+ | } | ||
+ | |||
+ | return requiredColumns; | ||
+ | } | ||
+ | |||
+ | private void ProcessOneWayRoad(BuildingRoutingDataRtgRoutingSourceEventArgs e, Feature roadFeature, Collection<string> oneWayColumns) | ||
+ | { | ||
+ | LineShape lineShape = GetLineShape(roadFeature); | ||
+ | |||
+ | // handled feature is one-way road | ||
+ | if (!roadFeature.ColumnValues[buildRtgParameter.OneWayRoadOption.OneWayColumnName].Equals(buildRtgParameter.OneWayRoadOption.BothWayRoadValue, StringComparison.InvariantCultureIgnoreCase)) | ||
+ | { | ||
+ | if (roadFeature.ColumnValues[buildRtgParameter.OneWayRoadOption.IndicatorColumnName].Equals(buildRtgParameter.OneWayRoadOption.FromToValue)) | ||
+ | { | ||
+ | e.RouteSegment.StartPointAdjacentIds.Clear(); | ||
+ | } | ||
+ | else if (roadFeature.ColumnValues[buildRtgParameter.OneWayRoadOption.IndicatorColumnName].Equals(buildRtgParameter.OneWayRoadOption.ToFromValue)) | ||
+ | { | ||
+ | e.RouteSegment.EndPointAdjacentIds.Clear(); | ||
+ | } | ||
+ | else if (roadFeature.ColumnValues[buildRtgParameter.OneWayRoadOption.IndicatorColumnName].Equals(buildRtgParameter.OneWayRoadOption.ClosedRoad)) | ||
+ | { | ||
+ | e.RouteSegment.StartPointAdjacentIds.Clear(); | ||
+ | e.RouteSegment.EndPointAdjacentIds.Clear(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // analysis adjacent one-way road features | ||
+ | Collection<string> removedStartPointAdjacentIds = GetRemovedAdjacentIds(e.RouteSegment.StartPointAdjacentIds, new PointShape(lineShape.Vertices[0]), oneWayColumns); | ||
+ | foreach (string id in removedStartPointAdjacentIds) | ||
+ | { | ||
+ | e.RouteSegment.StartPointAdjacentIds.Remove(id); | ||
+ | } | ||
+ | Collection<string> removedEndPointAdjacentIds = GetRemovedAdjacentIds(e.RouteSegment.EndPointAdjacentIds, new PointShape(lineShape.Vertices[lineShape.Vertices.Count|- 1]), oneWayColumns); | ||
+ | foreach (string id in removedEndPointAdjacentIds) | ||
+ | { | ||
+ | e.RouteSegment.EndPointAdjacentIds.Remove(id); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | private Collection<string> GetRemovedAdjacentIds(Collection<string> adjacentIds, PointShape intersectingPoint, Collection<string> oneWayColumns) | ||
+ | { | ||
+ | Collection<string> removedIds = new Collection<string>(); | ||
+ | foreach (string id in adjacentIds) | ||
+ | { | ||
+ | Feature adjacentFeature = routableFeatureSource.GetFeatureById(id, oneWayColumns); | ||
+ | if (!adjacentFeature.ColumnValues[buildRtgParameter.OneWayRoadOption.OneWayColumnName].Equals(buildRtgParameter.OneWayRoadOption.BothWayRoadValue, StringComparison.InvariantCultureIgnoreCase)) | ||
+ | { | ||
+ | LineShape adjacentLineShape = GetLineShape(adjacentFeature); | ||
+ | double distanceFromAdjacentStartToIntersecting = new PointShape(adjacentLineShape.Vertices[0]).GetDistanceTo(intersectingPoint, buildRtgParameter.GeographyUnit, buildRtgParameter.DistanceUnit); | ||
+ | double distanceFromAdjacentEndToIntersecting = new PointShape(adjacentLineShape.Vertices[adjacentLineShape.Vertices.Count|- 1]).GetDistanceTo(intersectingPoint, buildRtgParameter.GeographyUnit, buildRtgParameter.DistanceUnit); | ||
+ | if (distanceFromAdjacentStartToIntersecting <= distanceFromAdjacentEndToIntersecting | ||
+ | && adjacentFeature.ColumnValues[buildRtgParameter.OneWayRoadOption.IndicatorColumnName].Equals(buildRtgParameter.OneWayRoadOption.ToFromValue)) | ||
+ | { | ||
+ | removedIds.Add(id); | ||
+ | } | ||
+ | else if (distanceFromAdjacentEndToIntersecting <= distanceFromAdjacentStartToIntersecting | ||
+ | && adjacentFeature.ColumnValues[buildRtgParameter.OneWayRoadOption.IndicatorColumnName].Equals(buildRtgParameter.OneWayRoadOption.FromToValue)) | ||
+ | { | ||
+ | removedIds.Add(id); | ||
+ | } | ||
+ | else if (adjacentFeature.ColumnValues[buildRtgParameter.OneWayRoadOption.IndicatorColumnName].Equals(buildRtgParameter.OneWayRoadOption.ClosedRoad)) | ||
+ | { | ||
+ | removedIds.Add(id); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | return removedIds; | ||
+ | } | ||
+ | |||
+ | private float GetSpeed(String featureRoadSpeedClassValue) | ||
+ | { | ||
+ | float result = buildRtgParameter.SpeedOption.DefaultSpeed; | ||
+ | foreach (var item in buildRtgParameter.SpeedOption.RoadSpeeds) | ||
+ | { | ||
+ | if (item.Key.Equals(featureRoadSpeedClassValue, StringComparison.OrdinalIgnoreCase)) | ||
+ | { | ||
+ | result = (float)item.Value; | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | return result; | ||
+ | } | ||
+ | |||
+ | private static LineShape GetLineShape(Feature lineFeature) | ||
+ | { | ||
+ | BaseShape baseShape = lineFeature.GetShape(); | ||
+ | |||
+ | LineShape lineShape = baseShape as LineShape; | ||
+ | if (lineShape == null) | ||
+ | { | ||
+ | MultilineShape lineShapes = ((MultilineShape)baseShape); | ||
+ | Collection<Vertex> vertices = new Collection<Vertex>(); | ||
+ | |||
+ | foreach (LineShape line in lineShapes.Lines) | ||
+ | { | ||
+ | for (int i = 0; i < line.Vertices.Count; i++) | ||
+ | { | ||
+ | vertices.Add(line.Vertices[i]); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | lineShape = new LineShape(vertices); | ||
+ | lineShape.Id = baseShape.Id; | ||
+ | lineShape.Tag = baseShape.Tag; | ||
+ | } | ||
+ | |||
+ | return lineShape; | ||
+ | } | ||
+ | |||
+ | protected virtual void OnBuildingRouteSegment() | ||
+ | { | ||
+ | if (BuildingRouteSegment != null) | ||
+ | { | ||
+ | BuildingRouteSegment(this, new EventArgs()); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | </code> | ||
====Program.cs==== | ====Program.cs==== | ||
- | ^ Code ^ | + | |
- | | <source lang="csharp" line="1"> \\ using System; \\ using System.Collections.Generic; \\ using System.Linq; \\ using System.Windows.Forms; \\ \\ namespace RoutingIndexGenerator \\ { \\ static class Program \\ { \\ <nowiki>//</nowiki>/ <summary> \\ <nowiki>//</nowiki>/ The main entry point for the application. \\ <nowiki>//</nowiki>/ </summary> \\ [[STAThread]] \\ static void Main() \\ { \\ Application.EnableVisualStyles(); \\ Application.SetCompatibleTextRenderingDefault(false); \\ Application.Run(new RoutingIndexGenerator()); \\ } \\ } \\ } \\ \\ </source> | | + | <code csharp> |
+ | using System; | ||
+ | using System.Collections.Generic; | ||
+ | using System.Linq; | ||
+ | using System.Windows.Forms; | ||
+ | |||
+ | namespace RoutingIndexGenerator | ||
+ | { | ||
+ | static class Program | ||
+ | { | ||
+ | /// <summary> | ||
+ | /// The main entry point for the application. | ||
+ | /// </summary> | ||
+ | [STAThread] | ||
+ | static void Main() | ||
+ | { | ||
+ | Application.EnableVisualStyles(); | ||
+ | Application.SetCompatibleTextRenderingDefault(false); | ||
+ | Application.Run(new RoutingIndexGenerator()); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | </code> | ||
====SpeedUnit.cs==== | ====SpeedUnit.cs==== | ||
- | ^ Code ^ | + | |
- | | <source lang="csharp" line="1"> \\ \\ namespace RoutingIndexGenerator \\ { \\ public enum SpeedUnit \\ { \\ kilometer_hour = 0, \\ mile_hour = 1 \\ } \\ } \\ \\ </source> | | + | <code csharp> |
+ | |||
+ | namespace RoutingIndexGenerator | ||
+ | { | ||
+ | public enum SpeedUnit | ||
+ | { | ||
+ | kilometer_hour = 0, | ||
+ | mile_hour = 1 | ||
+ | } | ||
+ | } | ||
+ | |||
+ | </code> | ||
====SpeedType.cs==== | ====SpeedType.cs==== | ||
- | ^ Code ^ | + | |
- | | <source lang="csharp" line="1"> \\ \\ \\ namespace RoutingIndexGenerator \\ { \\ public enum SpeedType \\ { \\ RoadClass = 0, \\ RoadSpeed = 1, \\ DefaultSpeed = 2 \\ } \\ } \\ \\ </source> | | + | <code csharp> |
+ | |||
+ | |||
+ | namespace RoutingIndexGenerator | ||
+ | { | ||
+ | public enum SpeedType | ||
+ | { | ||
+ | RoadClass = 0, | ||
+ | RoadSpeed = 1, | ||
+ | DefaultSpeed = 2 | ||
+ | } | ||
+ | } | ||
+ | |||
+ | </code> | ||
====RouteIndexType.cs==== | ====RouteIndexType.cs==== | ||
- | ^ Code ^ | + | |
- | | <source lang="csharp" line="1"> \\ \\ \\ namespace RoutingIndexGenerator \\ { \\ public enum RouteIndexType \\ { \\ Fastest = 0, \\ Shortest = 1 \\ } \\ } \\ \\ \\ </source> | | + | <code csharp> |
+ | |||
+ | |||
+ | namespace RoutingIndexGenerator | ||
+ | { | ||
+ | public enum RouteIndexType | ||
+ | { | ||
+ | Fastest = 0, | ||
+ | Shortest = 1 | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | </code> | ||
====RoadSpeedOption.cs==== | ====RoadSpeedOption.cs==== | ||
- | ^ Code ^ | + | |
- | | <source lang="csharp" line="1"> \\ \\ using System.Collections.Generic; \\ \\ namespace RoutingIndexGenerator \\ { \\ public class RoadSpeedOption \\ { \\ private SpeedUnit speedUnit; \\ private float defaultSpeed; \\ private SpeedType speedType; \\ private string speedColumnName; \\ private string roadClassColumnName; \\ private Dictionary<string, double> roadSpeeds; \\ \\ public RoadSpeedOption() \\ { \\ DefaultSpeed = 60; \\ SpeedType = SpeedType.DefaultSpeed; \\ SpeedUnit = SpeedUnit.kilometer_hour; \\ } \\ \\ public SpeedUnit SpeedUnit \\ { \\ get { return speedUnit; } \\ set { speedUnit = value; } \\ } \\ \\ public float DefaultSpeed \\ { \\ get { return defaultSpeed; } \\ set { defaultSpeed = value; } \\ } \\ \\ public SpeedType SpeedType \\ { \\ get { return speedType; } \\ set { speedType = value; } \\ } \\ \\ public string SpeedColumnName \\ { \\ get { return speedColumnName; } \\ set { speedColumnName = value; } \\ } \\ \\ public string RoadClassColumnName \\ { \\ get { return roadClassColumnName; } \\ set { roadClassColumnName = value; } \\ } \\ \\ public Dictionary<string, double> RoadSpeeds \\ { \\ get \\ { \\ if (roadSpeeds == null) \\ { \\ roadSpeeds = new Dictionary<string, double>(); \\ } \\ return roadSpeeds; \\ } \\ } \\ } \\ } \\ \\ \\ </source> | | + | <code csharp> |
+ | |||
+ | using System.Collections.Generic; | ||
+ | |||
+ | namespace RoutingIndexGenerator | ||
+ | { | ||
+ | public class RoadSpeedOption | ||
+ | { | ||
+ | private SpeedUnit speedUnit; | ||
+ | private float defaultSpeed; | ||
+ | private SpeedType speedType; | ||
+ | private string speedColumnName; | ||
+ | private string roadClassColumnName; | ||
+ | private Dictionary<string, double> roadSpeeds; | ||
+ | |||
+ | public RoadSpeedOption() | ||
+ | { | ||
+ | DefaultSpeed = 60; | ||
+ | SpeedType = SpeedType.DefaultSpeed; | ||
+ | SpeedUnit = SpeedUnit.kilometer_hour; | ||
+ | } | ||
+ | |||
+ | public SpeedUnit SpeedUnit | ||
+ | { | ||
+ | get { return speedUnit; } | ||
+ | set { speedUnit = value; } | ||
+ | } | ||
+ | |||
+ | public float DefaultSpeed | ||
+ | { | ||
+ | get { return defaultSpeed; } | ||
+ | set { defaultSpeed = value; } | ||
+ | } | ||
+ | |||
+ | public SpeedType SpeedType | ||
+ | { | ||
+ | get { return speedType; } | ||
+ | set { speedType = value; } | ||
+ | } | ||
+ | |||
+ | public string SpeedColumnName | ||
+ | { | ||
+ | get { return speedColumnName; } | ||
+ | set { speedColumnName = value; } | ||
+ | } | ||
+ | |||
+ | public string RoadClassColumnName | ||
+ | { | ||
+ | get { return roadClassColumnName; } | ||
+ | set { roadClassColumnName = value; } | ||
+ | } | ||
+ | |||
+ | public Dictionary<string, double> RoadSpeeds | ||
+ | { | ||
+ | get | ||
+ | { | ||
+ | if (roadSpeeds == null) | ||
+ | { | ||
+ | roadSpeeds = new Dictionary<string, double>(); | ||
+ | } | ||
+ | return roadSpeeds; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | </code> | ||
====OneWayRoadOption.cs==== | ====OneWayRoadOption.cs==== | ||
- | ^ Code ^ | ||
- | | <source lang="csharp" line="1"> \\ \\ \\ namespace RoutingIndexGenerator \\ { \\ public class OneWayRoadOption \\ { \\ private string oneWayColumnName; \\ private string bothWayRoadValue; \\ private string indicatorColumnName; \\ private string fromToValue; \\ private string toFromValue; \\ private string closedRoad; \\ \\ public OneWayRoadOption() \\ { } \\ \\ public string OneWayColumnName \\ { \\ get { return oneWayColumnName; } \\ set { oneWayColumnName = value; } \\ } \\ \\ public string BothWayRoadValue \\ { \\ get { return bothWayRoadValue; } \\ set { bothWayRoadValue = value; } \\ } \\ \\ public string IndicatorColumnName \\ { \\ get { return indicatorColumnName; } \\ set { indicatorColumnName = value; } \\ } \\ \\ public string FromToValue \\ { \\ get { return fromToValue; } \\ set { fromToValue = value; } \\ } \\ \\ public string ToFromValue \\ { \\ get { return toFromValue; } \\ set { toFromValue = value; } \\ } \\ \\ public string ClosedRoad \\ { \\ get { return closedRoad; } \\ set { closedRoad = value; } \\ } \\ } \\ } \\ \\ \\ </source> | | ||
+ | <code csharp> | ||
+ | | ||
+ | | ||
+ | namespace RoutingIndexGenerator | ||
+ | { | ||
+ | public class OneWayRoadOption | ||
+ | { | ||
+ | private string oneWayColumnName; | ||
+ | private string bothWayRoadValue; | ||
+ | private string indicatorColumnName; | ||
+ | private string fromToValue; | ||
+ | private string toFromValue; | ||
+ | private string closedRoad; | ||
+ | | ||
+ | public OneWayRoadOption() | ||
+ | { } | ||
+ | | ||
+ | public string OneWayColumnName | ||
+ | { | ||
+ | get { return oneWayColumnName; } | ||
+ | set { oneWayColumnName = value; } | ||
+ | } | ||
+ | | ||
+ | public string BothWayRoadValue | ||
+ | { | ||
+ | get { return bothWayRoadValue; } | ||
+ | set { bothWayRoadValue = value; } | ||
+ | } | ||
+ | | ||
+ | public string IndicatorColumnName | ||
+ | { | ||
+ | get { return indicatorColumnName; } | ||
+ | set { indicatorColumnName = value; } | ||
+ | } | ||
+ | | ||
+ | public string FromToValue | ||
+ | { | ||
+ | get { return fromToValue; } | ||
+ | set { fromToValue = value; } | ||
+ | } | ||
+ | | ||
+ | public string ToFromValue | ||
+ | { | ||
+ | get { return toFromValue; } | ||
+ | set { toFromValue = value; } | ||
+ | } | ||
+ | | ||
+ | public string ClosedRoad | ||
+ | { | ||
+ | get { return closedRoad; } | ||
+ | set { closedRoad = value; } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | | ||
+ | </code> | ||
- | ====BuildRoutingIndexParameters.cs==== | ||
- | ^ Code ^ | ||
- | | <source lang="csharp" line="1"> \\ \\ using System.IO; \\ using ThinkGeo.MapSuite.Core; \\ using ThinkGeo.MapSuite.Routing; \\ \\ namespace RoutingIndexGenerator \\ { \\ public class BuildRoutingIndexParameters \\ { \\ private BuildRoutingDataMode buildRoutingDataMode; \\ private DistanceUnit distanceUnit; \\ private GeographyUnit geographyUnit; \\ private OneWayRoadOption oneWayRoadOption; \\ private RouteIndexType routeIndexType; \\ private string rtgFilePathName; \\ private string shapefilePathName; \\ private bool skipOnewayOptions; \\ private RoadSpeedOption speedOption; \\ \\ public BuildRoutingIndexParameters() \\ { \\ DistanceUnit = DistanceUnit.Meter; \\ RouteIndexType = RouteIndexType.Shortest; \\ GeographyUnit = GeographyUnit.DecimalDegree; \\ BuildRoutingDataMode = BuildRoutingDataMode.Rebuild; \\ \\ OneWayRoadOption = new OneWayRoadOption(); \\ SpeedOption = new RoadSpeedOption(); \\ } \\ \\ public BuildRoutingDataMode BuildRoutingDataMode \\ { \\ get { return buildRoutingDataMode; } \\ set { buildRoutingDataMode = value; } \\ } \\ \\ public DistanceUnit DistanceUnit \\ { \\ get { return distanceUnit; } \\ set { distanceUnit = value; } \\ } \\ \\ public GeographyUnit GeographyUnit \\ { \\ get { return geographyUnit; } \\ set { geographyUnit = value; } \\ } \\ \\ public OneWayRoadOption OneWayRoadOption \\ { \\ get { return oneWayRoadOption; } \\ set { oneWayRoadOption = value; } \\ } \\ \\ public RouteIndexType RouteIndexType \\ { \\ get { return routeIndexType; } \\ set { routeIndexType = value; } \\ } \\ \\ public string RtgFilePathName \\ { \\ get { return rtgFilePathName; } \\ set \\ { \\ rtgFilePathName = !string.IsNullOrEmpty(value) ? Path.ChangeExtension(value, ".rtg") : string.Empty; \\ } \\ } \\ \\ public string ShapefilePathName \\ { \\ get { return shapefilePathName; } \\ set \\ { \\ shapefilePathName = value; \\ RtgFilePathName = Path.ChangeExtension(shapefilePathName, ".rtg"); \\ } \\ } \\ \\ public bool SkipOnewayOptions \\ { \\ get { return skipOnewayOptions; } \\ set { skipOnewayOptions = value; } \\ } \\ \\ public RoadSpeedOption SpeedOption \\ { \\ get { return speedOption; } \\ set { speedOption = value; } \\ } \\ \\ public bool CheckCanBuildIndexFile() \\ { \\ bool result = SpeedOption.DefaultSpeed != 0; \\ try \\ { \\ ShapeFileFeatureLayer layer = new ShapeFileFeatureLayer(ShapefilePathName); \\ layer.Open(); \\ ShapeFileType fileType = layer.GetShapeFileType(); \\ layer.Close(); \\ \\ if (fileType != ShapeFileType.Polyline) \\ { \\ result = false; \\ } \\ } \\ catch \\ { \\ result = false; \\ } \\ \\ if (result && string.IsNullOrEmpty(rtgFilePathName)) \\ { \\ result = false; \\ } \\ else if (result && !SkipOnewayOptions && (string.IsNullOrEmpty(OneWayRoadOption.BothWayRoadValue) \\ || string.IsNullOrEmpty(OneWayRoadOption.FromToValue) || string.IsNullOrEmpty(OneWayRoadOption.ToFromValue) \\ || string.IsNullOrEmpty(OneWayRoadOption.IndicatorColumnName) || string.IsNullOrEmpty(OneWayRoadOption.OneWayColumnName))) \\ { \\ result = false; \\ } \\ else if ((result && SpeedOption.SpeedType == SpeedType.RoadClass) \\ && (string.IsNullOrEmpty(SpeedOption.RoadClassColumnName) || SpeedOption.RoadSpeeds.Count == 0)) \\ { \\ result = false; \\ } \\ else if (result && SpeedOption.SpeedType == SpeedType.RoadSpeed \\ && string.IsNullOrEmpty(SpeedOption.SpeedColumnName)) \\ { \\ result = false; \\ } \\ \\ return result; \\ } \\ } \\ } \\ \\ </source> | | ||
+ | ====BuildRoutingIndexParameters.cs==== | ||
+ | <code csharp> | ||
+ | | ||
+ | using System.IO; | ||
+ | using ThinkGeo.MapSuite.Core; | ||
+ | using ThinkGeo.MapSuite.Routing; | ||
+ | | ||
+ | namespace RoutingIndexGenerator | ||
+ | { | ||
+ | public class BuildRoutingIndexParameters | ||
+ | { | ||
+ | private BuildRoutingDataMode buildRoutingDataMode; | ||
+ | private DistanceUnit distanceUnit; | ||
+ | private GeographyUnit geographyUnit; | ||
+ | private OneWayRoadOption oneWayRoadOption; | ||
+ | private RouteIndexType routeIndexType; | ||
+ | private string rtgFilePathName; | ||
+ | private string shapefilePathName; | ||
+ | private bool skipOnewayOptions; | ||
+ | private RoadSpeedOption speedOption; | ||
+ | | ||
+ | public BuildRoutingIndexParameters() | ||
+ | { | ||
+ | DistanceUnit = DistanceUnit.Meter; | ||
+ | RouteIndexType = RouteIndexType.Shortest; | ||
+ | GeographyUnit = GeographyUnit.DecimalDegree; | ||
+ | BuildRoutingDataMode = BuildRoutingDataMode.Rebuild; | ||
+ | | ||
+ | OneWayRoadOption = new OneWayRoadOption(); | ||
+ | SpeedOption = new RoadSpeedOption(); | ||
+ | } | ||
+ | | ||
+ | public BuildRoutingDataMode BuildRoutingDataMode | ||
+ | { | ||
+ | get { return buildRoutingDataMode; } | ||
+ | set { buildRoutingDataMode = value; } | ||
+ | } | ||
+ | | ||
+ | public DistanceUnit DistanceUnit | ||
+ | { | ||
+ | get { return distanceUnit; } | ||
+ | set { distanceUnit = value; } | ||
+ | } | ||
+ | | ||
+ | public GeographyUnit GeographyUnit | ||
+ | { | ||
+ | get { return geographyUnit; } | ||
+ | set { geographyUnit = value; } | ||
+ | } | ||
+ | | ||
+ | public OneWayRoadOption OneWayRoadOption | ||
+ | { | ||
+ | get { return oneWayRoadOption; } | ||
+ | set { oneWayRoadOption = value; } | ||
+ | } | ||
+ | | ||
+ | public RouteIndexType RouteIndexType | ||
+ | { | ||
+ | get { return routeIndexType; } | ||
+ | set { routeIndexType = value; } | ||
+ | } | ||
+ | | ||
+ | public string RtgFilePathName | ||
+ | { | ||
+ | get { return rtgFilePathName; } | ||
+ | set | ||
+ | { | ||
+ | rtgFilePathName = !string.IsNullOrEmpty(value) ? Path.ChangeExtension(value, ".rtg") : string.Empty; | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | public string ShapefilePathName | ||
+ | { | ||
+ | get { return shapefilePathName; } | ||
+ | set | ||
+ | { | ||
+ | shapefilePathName = value; | ||
+ | RtgFilePathName = Path.ChangeExtension(shapefilePathName, ".rtg"); | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | public bool SkipOnewayOptions | ||
+ | { | ||
+ | get { return skipOnewayOptions; } | ||
+ | set { skipOnewayOptions = value; } | ||
+ | } | ||
+ | | ||
+ | public RoadSpeedOption SpeedOption | ||
+ | { | ||
+ | get { return speedOption; } | ||
+ | set { speedOption = value; } | ||
+ | } | ||
+ | | ||
+ | public bool CheckCanBuildIndexFile() | ||
+ | { | ||
+ | bool result = SpeedOption.DefaultSpeed != 0; | ||
+ | try | ||
+ | { | ||
+ | ShapeFileFeatureLayer layer = new ShapeFileFeatureLayer(ShapefilePathName); | ||
+ | layer.Open(); | ||
+ | ShapeFileType fileType = layer.GetShapeFileType(); | ||
+ | layer.Close(); | ||
+ | | ||
+ | if (fileType != ShapeFileType.Polyline) | ||
+ | { | ||
+ | result = false; | ||
+ | } | ||
+ | } | ||
+ | catch | ||
+ | { | ||
+ | result = false; | ||
+ | } | ||
+ | | ||
+ | if (result && string.IsNullOrEmpty(rtgFilePathName)) | ||
+ | { | ||
+ | result = false; | ||
+ | } | ||
+ | else if (result && !SkipOnewayOptions && (string.IsNullOrEmpty(OneWayRoadOption.BothWayRoadValue) | ||
+ | || string.IsNullOrEmpty(OneWayRoadOption.FromToValue) || string.IsNullOrEmpty(OneWayRoadOption.ToFromValue) | ||
+ | || string.IsNullOrEmpty(OneWayRoadOption.IndicatorColumnName) || string.IsNullOrEmpty(OneWayRoadOption.OneWayColumnName))) | ||
+ | { | ||
+ | result = false; | ||
+ | } | ||
+ | else if ((result && SpeedOption.SpeedType == SpeedType.RoadClass) | ||
+ | && (string.IsNullOrEmpty(SpeedOption.RoadClassColumnName) || SpeedOption.RoadSpeeds.Count == 0)) | ||
+ | { | ||
+ | result = false; | ||
+ | } | ||
+ | else if (result && SpeedOption.SpeedType == SpeedType.RoadSpeed | ||
+ | && string.IsNullOrEmpty(SpeedOption.SpeedColumnName)) | ||
+ | { | ||
+ | result = false; | ||
+ | } | ||
+ | | ||
+ | return result; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | </code> |