User Tools

Site Tools


source_code_routing_index_generator_cs_100325.zip

This is an old revision of the document!


Source_Code_Routing_Index_Generator_CS_100325.zip

<noinclude>article_rating</noinclude>

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();

//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.StartNew1);
}

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 stringsource_code_routing_index_generator_cs_100325.zip { cmbRoadClassColumn.Text });
source.Close();

foreach (Feature feature in features)
{
if (!colRoadClass.Items.Contains(feature.ColumnValuescmbRoadClassColumn.Text))
{
colRoadClass.Items.Add(feature.ColumnValuescmbRoadClassColumn.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.Cells1.Value == null ? string.Empty : row.Cells1.Value.ToString();
string key = row.Cellsmain_page.Value == null ? string.Empty : row.Cellsmain_page.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);
}
}
}
}


</source>

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)
{
// 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.ColumnValuesbuildRtgParameter.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.ColumnValuesbuildRtgParameter.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.ColumnValuesbuildRtgParameter.OneWayRoadOption.OneWayColumnName.Equals(buildRtgParameter.OneWayRoadOption.BothWayRoadValue, StringComparison.InvariantCultureIgnoreCase))
{
if (roadFeature.ColumnValuesbuildRtgParameter.OneWayRoadOption.IndicatorColumnName.Equals(buildRtgParameter.OneWayRoadOption.FromToValue))
{
e.RouteSegment.StartPointAdjacentIds.Clear();
}
else if (roadFeature.ColumnValuesbuildRtgParameter.OneWayRoadOption.IndicatorColumnName.Equals(buildRtgParameter.OneWayRoadOption.ToFromValue))
{
e.RouteSegment.EndPointAdjacentIds.Clear();
}
else if (roadFeature.ColumnValuesbuildRtgParameter.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.Verticesmain_page), oneWayColumns);
foreach (string id in removedStartPointAdjacentIds)
{
e.RouteSegment.StartPointAdjacentIds.Remove(id);
}
Collection<string> removedEndPointAdjacentIds = GetRemovedAdjacentIds(e.RouteSegment.EndPointAdjacentIds, new PointShape(lineShape.Vertices- 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.ColumnValuesbuildRtgParameter.OneWayRoadOption.OneWayColumnName.Equals(buildRtgParameter.OneWayRoadOption.BothWayRoadValue, StringComparison.InvariantCultureIgnoreCase))
{
LineShape adjacentLineShape = GetLineShape(adjacentFeature);
double distanceFromAdjacentStartToIntersecting = new PointShape(adjacentLineShape.Verticesmain_page).GetDistanceTo(intersectingPoint, buildRtgParameter.GeographyUnit, buildRtgParameter.DistanceUnit);
double distanceFromAdjacentEndToIntersecting = new PointShape(adjacentLineShape.Vertices- 1).GetDistanceTo(intersectingPoint, buildRtgParameter.GeographyUnit, buildRtgParameter.DistanceUnit);
if (distanceFromAdjacentStartToIntersecting ⇐ distanceFromAdjacentEndToIntersecting
&& adjacentFeature.ColumnValuesbuildRtgParameter.OneWayRoadOption.IndicatorColumnName.Equals(buildRtgParameter.OneWayRoadOption.ToFromValue))
{
removedIds.Add(id);
}
else if (distanceFromAdjacentEndToIntersecting ⇐ distanceFromAdjacentStartToIntersecting
&& adjacentFeature.ColumnValuesbuildRtgParameter.OneWayRoadOption.IndicatorColumnName.Equals(buildRtgParameter.OneWayRoadOption.FromToValue))
{
removedIds.Add(id);
}
else if (adjacentFeature.ColumnValuesbuildRtgParameter.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 = 2);
}
}
}
}


</source>

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
{
/// <summary>
/// The main entry point for the application.
/// </summary>
STAThread
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new RoutingIndexGenerator());
}
}
}

</source>

SpeedUnit.cs

Code
<source lang=“csharp” line=“1”>

namespace RoutingIndexGenerator
{
public enum SpeedUnit
{
kilometer_hour = 0,
mile_hour = 1
}
}

</source>

SpeedType.cs

Code
<source lang=“csharp” line=“1”>


namespace RoutingIndexGenerator
{
public enum SpeedType
{
RoadClass = 0,
RoadSpeed = 1,
DefaultSpeed = 2
}
}

</source>

RouteIndexType.cs

Code
<source lang=“csharp” line=“1”>


namespace RoutingIndexGenerator
{
public enum RouteIndexType
{
Fastest = 0,
Shortest = 1
}
}


</source>

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>

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>

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 3)
{
result = false;
}
else if (result && SpeedOption.SpeedType == SpeedType.RoadSpeed
&& string.IsNullOrEmpty(SpeedOption.SpeedColumnName))
{
result = false;
}

return result;
}
}
}

</source>
1) ) ⇒
{
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”);
}
}
2) 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.Verticesi);
}
}

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(
3) result && SpeedOption.SpeedType == SpeedType.RoadClass)
&& (string.IsNullOrEmpty(SpeedOption.RoadClassColumnName) || SpeedOption.RoadSpeeds.Count == 0
source_code_routing_index_generator_cs_100325.zip.1440040125.txt.gz · Last modified: 2015/09/09 03:33 (external edit)