ThinkGeo.com    |     Documentation    |     Premium Support

Using Routing with SQLite?

I’ve started the next part of our prototype application.  I have GeoCoding working and Vehicle Location working.  Now I am working on Routing.  I downloaded the CityRoutingAndDirections_Desktop example.  I see it uses the local austin shape files.  How would I go about using the SQLite database instead?  I wasn’t able to find a demo like that.  For our other examples we are using the OSMWorldMapKit class library to load the SQLite data.



Thank you in advance for your guidance.

Hi Dave,


The “SqliteFeatureLayer” in the
extension “SQLiteExtension.dll” can be used to load data from Sqlite database,
please have a try.


Here is a demo you
can download to see how to create routing index file (*.rtg) and route with
shape file (*.shp) and *.sqlite, please have a try. One thing please remember
is getting the latest version of MapSuiteRouting extension 9.0.119.0 or later.



Thanks,

Peter



Hi Peter. I am running the demo.  I have referenced all the latest DLLs and I am using the latest SQLite database.  I am getting an error after I select the database “An unhandled exception of type ‘System.AccessViolationException’ occurred in System.Data.SQLite.dll”.  Attached is a screen shot of the error. Occurs in RoutingIndexGenerator.cs on line 79.  Any thoughts as to why this occurs?








Hi Dave,


I guess this problem is caused
by the different version of the DLLs. Please use NuGet to install
“System.Data.SQLite” version 1.0.98.0 or later for the Project. Attached is
screenshot. Search "SQLite.Data.SQLite" to install.



Any questions let me know.



Thanks,

Peter



I was able to generate the Routing indexes for New Jersey.  I took your routing demo and replaced the austin streets with my new New Jersey streets.  Didn’t work. 
  
 I then looked at the databases and they are completely different.  The austin demo seems to use FULL_STREE at the street name where as the generated Database uses name?  So I changed that and the app now sits there for about 10 minutes before finally showing the main form and then crashes. 
  
 Is there a real working demo that works with the real generated indexes?  This seems to be the case with many of the ThinkGeo demos.  They are all built around the Austin Streets data and are not easily modified or adapted.

Hi Dave,



The “FULL_STREE” Just a column name of database to show information to user.



I am not sure how you create and use the index file(".rtg"). Please try following steps.

1. Create routing index file from “.sqlite” using Routing Index Generator, the “Geography Unit” must be the same as geography unit of “.sqlite”.



2. Use SqliteFeatureLayer to load features from “.sqlite” file as following.


routingFeatureLayer = new SqliteFeatureLayer(connectionString, “osm_road5m_linestring”, “id”, “geometry”);

3. Set the GeographyUnit of RoutingEngine following the same Geography Unit of “.rtg” (look the attached above) as following:


RoutingEngine routingEngine = new RoutingEngine(new RtgRoutingSource(rtgFilePathName), routingFeatureLayer.FeatureSource);
routingEngine.GeographyUnit = GeographyUnit.Meter; //Set the GeographyUnit.

Any questions please let me know.



Thanks,

Peter

Ok with the changes it now sits there for about 30 seconds without showing a form, then it throws an error on this highlighted line.  The error say it cannot convert a MulilineShape to a MultipolygonShape.


private void InitRestrictedOverlay()
{
    LayerOverlay restrictedOverlay = new LayerOverlay();
    mapControl.Overlays.Add("RestrictedOverlay", restrictedOverlay);
 
    const string newjerseyCountyShapeFile = @"D:\ThinkGeo\NewJersey.fastest.routable.shp";
    ShapeFileFeatureLayer restrictedLayer = new ShapeFileFeatureLayer(newjerseyCountyShapeFile);
    restrictedLayer.Open();
    restrictedPolygon = (MultipolygonShape)restrictedLayer.QueryTools.GetAllFeatures(ReturningColumnsType.AllColumns)[0].GetShape();
    AreaStyle extentStyle = new AreaStyle();
    extentStyle.CustomAreaStyles.Add(new AreaStyle(new GeoSolidBrush(GeoColor.SimpleColors.Transparent)) { OutlinePen = new GeoPen(GeoColor.SimpleColors.White, 5.5f) });
    extentStyle.CustomAreaStyles.Add(new AreaStyle(new GeoSolidBrush(GeoColor.SimpleColors.Transparent)) { OutlinePen = new GeoPen(GeoColor.SimpleColors.Red, 1.5f) { DashStyle = LineDashStyle.Dash } });
    restrictedLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = extentStyle;
    restrictedLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
    restrictedOverlay.Layers.Add("RestrictedLayer", restrictedLayer);
}

If I just bypass this code to keep going, everything loads.  I choose two points and hit the Get Directions button and it does nothing.

The results variable shows 0 for counts.


RoutingResult result = routePathAndDirection.GetRoute();


Hi Dave,



The reason is the SearchRadiusInMeters property of RoutingEngine is too  small (default value is 20 meters). Please try changing the value to bigger before calling “GetRoute” method as following.


RoutePathAndDirection routePathAndDirection = new RoutePathAndDirection(routingEngine, routingLayer.StartPoint, routingLayer.EndPoint, barrierLayer.FeatureSource, avoidableFeatureIds, routingLayer.StopPoints);

routingEngine.SearchRadiusInMeters = 100;

RoutingResult result = routePathAndDirection.GetRoute();




The another way to make it work is setting the StartPoint and EndPoint of RoutingLayer in  like following:


routingFeatureLayer.Open();
Collection<Feature> nearestFeatures = routingFeatureLayer.FeatureSource.GetFeaturesNearestTo(clickedMouseWorldPoint, mapControl.MapUnit, 1, new string[] { roadColumnName });
routingFeatureLayer.Close();
var selectFeature = nearestFeatures[0];
LineBaseShape line = selectFeature.GetShape() as LineBaseShape;
PointShape point = line.GetClosestPointTo(clickedMouseWorldPoint, mapControl.MapUnit);
routingLayer.StartPoint = point; //Set StartPoint or EndPoint here.






The following is the screenshot on my side.







Thanks,

Peter

Peter,



I tried adding in the search radius line of code.  While it does now appear to route the results are not correct.  From my Point A to my Point B on Fastest it created an odd loop.  Using Shortest the loop was much the same with slight variation.





When I use your second Suggestion (I removed the search radius line of code not sure if that is right) it seems to move the start and end point markers either to the same location or to completely different locations on the map then creates a very crazy random route.



This started with your routing demo from your site.  Can I archive this and send it over.  Perhaps you will find something glaringly wrong with the demo or the changes I made (although they are minor).  I just feel we’ve made no progress in the last few days in the forums when this should have been as simple as downloading your demo, change the routing files, and we’re off and running.  Both my Boss and I are getting a bit frustrated with the lack of real world examples and the ability build working routing systems with the tools provided.

Hi Dave,



Could you please send the demo to forumsupport@thinkgeo.com. If the size is bigger than 20M, please transfer it by FTP, more information at here



Thanks,
Peter

Hi Dave,



Thanks for the sample. I checked the resource and did some changes here. Please download it at here



It works well by reference the DLLs( version 9.0.0.125) which can be download from Product Center.



If it’s still not work right on your side, could you please attach the data files(".rtg", “*.sqlite”) or send them to forumsupport@thinkgeo.com.



Thanks,
Peter




Peter,



As soon I downloaded the project, I fixed the references and then pointed at the shape files that were created by the route index generator tool. The map shows blank.



Looking at the code that you commented out is a concern to me.  By doing this, are you saying that we cannot use SQLite as the shape source for this?



In the end we are trying to build a comprehensive application that has GeoCoding (customer address markers), Vehicle Tracking (we’re using OSMWorldMapKit and SQLite) and routing.  We want to have the ability to allow them to view and create routes for the Customer Markers.  It seems there is not one data solution with ThinkGeo.  We are ok with distributing the Tiger Data for GeoCoding and the SQLite Data for the other Mapping.  Having to generate all kinds of other data for routing doesn’t seem practical.  We have 50+ customers who will be using our application.  They service locations all over the USA and CANADA.



For instance we may have a client in Connecticut who services 50 miles radius from their office.  Then we may have a customer in Alberta Canada who services 250 miles radius from their office.  Both will be using the same software.



If we have to create all different types of routing data for these clients spread all over the USA and CANADA, I think we cannot provide them a routing solution in this case.  The time to create all of these scenarios of data would be outrageous.



I will also send you my routing data for New Jersey because I would at a minimum like to see this work since I have never seen ThinkGeo route outside of Austin.

Hi Dave, 
  
 We are working on it. 
  
 Any updates will let you know. 
  
 Thanks, 
 Peter