I have several layers that make up my road network; one shapefile for highways, one for major roads, one for local roads. For the routing engine to work should I combine all of these shapefiles into one and then create a Routing Index from that? Or, should I create seperate routing index files for each of my road shapefiles?
Routing Indexes - Combine Shapefiles or Create Individual Indexes for each
Steve,
Yes, we recommend you to combine all the shape files into one and then create a Routing index from that, this is the best way for now. Another way is using MultipleShapeFileFeatureSource instead of combining all the shape files, it is a bit slower though. Here is the sample code how to route with that.
1. Build multi shape file index:
MultipleShapeFileFeatureLayer.BuildIndex("testdata*.shp", BuildIndexMode.Rebuild);
2. Build Routing index:
MultipleShapeFileFeatureSource featureSource = new MultipleShapeFileFeatureSource("testdata*.shp");
featureSource.Open();
RtgRoutingSource.GenerateRoutingData("testdata.rtg", featureSource, BuildRoutingDataMode.Rebuild);
3. Route:
MultipleShapeFileFeatureSource featureSource = new MultipleShapeFileFeatureSource(dictionary + "testdata*.shp");
RtgRoutingSource routingSource = new RtgRoutingSource(dictionary + "testdata.rtg");
RoutingEngine routingEngine = new RoutingEngine(routingSource, featureSource);
routingLayer.Routes.Clear();
routingLayer.Routes.Add(routingEngine.GetRoute(startFeatureId, endFeatureId).Route);
winformsMap1.Overlays["RoutingOverlay"].Lock.IsDirty = true;
winformsMap1.Refresh();
We are working on this to make it easier to use. Any questions/comments/suggestions please let us know.
Thanks!
Ben
I had the same scenario as Steve, my road network layers are seperated into multiple shapefiles. I've used the code given in this post to create the routing index, and like Ben said, it is really slow. I've put in a request with my data provider to supply combined shape files but in case they can't, wouldn't this procedure execute much faster if the method was re-written across multiple threads? Surely it'd be able to make the most out of the processor - my mapping server is a quad-box and would probably see a lot of benefit
Rikus,
Welcome to the MapSuite Discussion forum.
Could you let me know what’s the size of your shape files, how many records it has and how much time it takes? Just wonder how slow it is. The RtgRoutingSource.GenerateRoutableShapeFile is a static API which cannot be re-written, but we are reviewing our procedure and checking if we can improve it (like using multiple threads or use some other ways). Thanks for the suggestion!
Thanks,
Ben.
I'm still waiting for my data provider to supply me a combined shapefile or maybe split them into smaller regions, but the details of my road layers are:
Roads Main (Main roads) : 10,800 records in 8,621 KB
Roads Major (Freeways) : 1,866 records in 2,059 KB
Roads Ramp (On ramps, off ramps and slipways) : 4,134 records in 1,093 KB
Roads Sec (Secondary roads) : 15,902 records in 24,908 KB
Roads Sub (Suburban roads) : 320,903 records in 110,181 KB
I had to cancel building the routing index after it took me a week to run through just under 10,000 records out of aboout 350,000 and create a 681 KB Roads.rtg file
Rikus,
This is a dumb question but I am willing to ask it. The shape files you mention above do you have index files build for them. These would be files that end in .Idx and .Sdx? These are index files for the shape files themselves and not for routing, these files greatly increase the speed at which we can process shape files in our products.
When you ran the code to build the multi index, if you did, then what was the size of the multi index file it created? I wonder if some index is not getting built before we start building the routing index.
David
Rikus,
One more thing to look for would me files with a .Midx and Mids as well. Let me know if you see any of them and their size.
David
Each of the shape files have .idx and .sbx files (I have .sBx not .sDx) as well as .dbf, .ids, .prj, .sbn and .shx files. I've attached an image of the sizes of the .mids and .midx files. The screenshot is ordered by date modified, so you can see how long it took in between building each of the indexes and when the first entry in the rtg was made. I'll paste my code as well. The progress counter says there's a total of 353,605 records.
MultipleShapeFileFeatureLayer.BuildIndex(path + "ROAD*.shp", BuildIndexMode.Rebuild);
MultipleShapeFileFeatureSource featureSource = new MultipleShapeFileFeatureSource(path + "ROAD*.shp");
featureSource.Open();
pgBuildingData.Maximum = featureSource.GetCount();
lbTotalCount.Text = pgBuildingData.Maximum.ToString(CultureInfo.InvariantCulture);
featureSource.Close();
RtgRoutingSource.GenerateRoutingData(path + "ROADS.rtg", featureSource, BuildRoutingDataMode.Rebuild);
Rikus,
We did a test with two shape files (63M) and proved that it’s really slow when building the routing index using MultipleShapeFileFeatureSource. I think that’s an issue and we will try to fix it in the next release, now combining them into a single shape file is the best way. The attachment (CombineShapeFiles.zip) is a tool for merging Shape files and one note for that is please make sure all the shape files have the same Dbf columns.
Any question please let us know, Thanks!
Ben.
1172-CombineShapeFiles.zip (11.3 KB)