I tried creating the rtg file using the tool and it worked.
When I tried to do the routing in the application it is saying “No Route found”
App.config
Added the following code in worldStreetsLayerSample - Form1.cs
startFeature = new Feature(new PointShape(-96.80629120, 32.79319788));
endFeature = new Feature(new PointShape(-96.72749863, 32.81208063));
pointLayer.InternalFeatures.Add(startFeature);
pointLayer.InternalFeatures.Add(endFeature);
private void AddRoutingLayer()
{
featureSource = new ShapeFileFeatureSource(Path.Combine(
ConfigurationManager.AppSettings[“RouteBasePath”],
ConfigurationManager.AppSettings[“SourceShapeFile”]));
routingSource = new RtgRoutingSource(Path.Combine(
ConfigurationManager.AppSettings["RouteBasePath"],
ConfigurationManager.AppSettings["FastRouteFile"]));
routingEngine = new RoutingEngine(routingSource, featureSource);
routingEngine.RoutingAlgorithm.FindingRoute += new EventHandler<FindingRouteRoutingAlgorithmEventArgs>(RoutingAlgorithm_FindingRoute);
isAddingRoadblocks = false;
avoidableFeatureIds = new Collection<string>();
routingLayer = new RoutingLayer();
routingLayer.StartPoint = new PointShape(startFeature.GetWellKnownBinary());
routingLayer.EndPoint = new PointShape(endFeature.GetWellKnownBinary());
routingOverlay = new LayerOverlay();
routingOverlay.Layers.Add("PHX_RoutingLayer", routingLayer);
winformsMap1.Overlays.Add("RoutingOverlay", routingOverlay);
roadblocksLayer = new InMemoryFeatureLayer();
roadblocksLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = new PointStyle(new GeoImage(
ConfigurationManager.AppSettings["RouteBasePath"] + "RoadBlock.png"));
roadblocksLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
routingOverlay.Layers.Add("roadblocksLayer", roadblocksLayer);
InMemoryFeatureLayer routingExtentLayer = new InMemoryFeatureLayer();
routingExtentLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(new GeoPen(GeoColor.SimpleColors.Green));
routingExtentLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
routingExtentLayer.InternalFeatures.Add(new Feature(
new RectangleShape(-96.930929, 32.878436, -96.640798, 32.710878)));
routingOverlay.Layers.Add("RoutingExtentLayer", routingExtentLayer);
}
void RoutingAlgorithm_FindingRoute(object sender, FindingRouteRoutingAlgorithmEventArgs e)
{
Collection<string> startPointAdjacentIds = e.RouteSegment.StartPointAdjacentIds;
Collection<string> endPointAdjacentIds = e.RouteSegment.EndPointAdjacentIds;
Collection<string> beContainedFeatureIds = new Collection<string>();
foreach (string featureId in startPointAdjacentIds)
{
if (avoidableFeatureIds.Contains(featureId))
{
beContainedFeatureIds.Add(featureId);
}
}
foreach (string featureId in endPointAdjacentIds)
{
if (avoidableFeatureIds.Contains(featureId))
{
beContainedFeatureIds.Add(featureId);
}
}
// Remove the ones that be contained in the avoidable area
foreach (string id in beContainedFeatureIds)
{
if (e.RouteSegment.StartPointAdjacentIds.Contains(id))
{
e.RouteSegment.StartPointAdjacentIds.Remove(id);
}
if (e.RouteSegment.EndPointAdjacentIds.Contains(id))
{
e.RouteSegment.EndPointAdjacentIds.Remove(id);
}
}
}
private void Route()
{
RoutingLayer routingLayer =
(RoutingLayer)((LayerOverlay)winformsMap1.Overlays["RoutingOverlay"]).Layers["PHX_RoutingLayer"];
avoidableFeatureIds.Clear();
foreach (Feature feature in roadblocksLayer.InternalFeatures)
{
avoidableFeatureIds.Add(feature.Id);
}
routingLayer.Routes.Clear();
RoutingResult routingResult = routingEngine.GetRoute(routingLayer.StartPoint, routingLayer.EndPoint);
if (routingResult.Features.Count == 0)
{
MessageBox.Show("No route exists!");
}
else
{
routingLayer.Routes.Add(routingResult.Route);
}
winformsMap1.Refresh(winformsMap1.Overlays["RoutingOverlay"]);
}