Hi Thinkgeo (and Community),
I am currently trying to find any route based on tab-Files. In order to do this, I first converted my .tab files to .shp files using ogr2ogr. Afterwards I managed to display certain start and end points using the id’s as proposed in the Getting-Started-Example.
When I call GetRoute, I get an ArgumentOutOfRange Exception. I’m pretty sure there’s something wrong with my code (it’s almost the same es in the examples):
winformsMap1.MapUnit = GeographyUnit.Meter;
winformsMap1.ThreadingMode = MapThreadingMode.SingleThreaded;
WorldMapKitWmsDesktopOverlay worldMapKitDesktopOverlay = new WorldMapKitWmsDesktopOverlay();
winformsMap1.Overlays.Add(worldMapKitDesktopOverlay);
winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);
ShapeFileFeatureLayer routableStreetsLayer = new ShapeFileFeatureLayer(@“Roads1Full.shp”);
routableStreetsLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.LocalRoad4;
routableStreetsLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
LayerOverlay routableStreetOverlay = new LayerOverlay();
routableStreetOverlay.Layers.Add(“routableStreets”, routableStreetsLayer);
winformsMap1.Overlays.Add(“routingStreetOverlay”, routableStreetOverlay);
FeatureSource featureSource;
featureSource = new ShapeFileFeatureSource(@“Roads1Full.shp”);
RtgRoutingSource.GenerateRoutingData(@“Roads1Full_routable.rtg”, featureSource, BuildRoutingDataMode.Rebuild, GeographyUnit.Meter, DistanceUnit.Meter);
RoutingLayer routingLayer = new RoutingLayer();
routableStreetsLayer.Open();
routingLayer.StartPoint = routableStreetsLayer.FeatureSource.GetFeatureById(“1”, ReturningColumnsType.NoColumns).GetShape().GetCenterPoint();
routingLayer.EndPoint = routableStreetsLayer.FeatureSource.GetFeatureById(“500”, ReturningColumnsType.NoColumns).GetShape().GetCenterPoint();
routableStreetsLayer.Close();
LayerOverlay routingOverlay = new LayerOverlay();
routingOverlay.Layers.Add(“RoutingLayer”, routingLayer);
winformsMap1.Overlays.Add(“RoutingOverlay”, routingOverlay);
RtgRoutingSource routingSource = new RtgRoutingSource(@“Roads1Full_routable.rtg”);
RoutingEngine routingEngine = new RoutingEngine(routingSource, featureSource);
routingLayer = (RoutingLayer)((LayerOverlay)winformsMap1.Overlays[“RoutingOverlay”]).Layers[“RoutingLayer”];
winformsMap1.Overlays[“RoutingOverlay”].Lock.EnterWriteLock();
try
{
routingLayer.Routes.Clear();
routingLayer.Routes.Add(routingEngine.GetRoute(“1”, “500”).Route);
}
finally
{
winformsMap1.Overlays[“RoutingOverlay”].Lock.ExitWriteLock();
}
winformsMap1.Refresh();
When I load the .shp and its corresponding .rtg file into the MapSuite Routing Explorer, some routes can be calculated, some can’t. In case the calculation is successful, there are sometimes really weird routes, leaving the streets or taking strange detours. Maybe there’s anything wrong with my .rtg files - or maybe my streets are not really associated? I don’t get it.
Thanks in advance for your help!
Roads1Full.zip (1.34 MB)