none
CalculateDirection and get the polyline RRS feed

  • Question

  • Hi all and sorry for my bad english,

    is it possible to get the polyline of a road which result of the direcionManager.Getdirection method?

    The goal is calculate a road, get the polyline, transform it in a sqlGeography instance in order to see if the route intersects some points in my database (STIntersect)...

    Now, I'm able to get the decodedLatitudes and decodedLongitudes array for each routeLegs in the Road, but I must make manually conversion to have sqlGeography instance (with a lot of problem if the road have the same points more than once or other...).

    Is bing map able to give me a geoJson or sqlgeography format or any geographic format after calculateDirection?

    I think it must be possible because Bing and SqlServer are microsoft products...

    Thank you for your help !!!

    Thursday, October 24, 2013 8:07 AM

Answers

  • I have done this many times. The best approach is to calculate the route on the server side rather than in the client app. This way you won't need to send the route data to the server from your app. Using the Bing Maps REST services to get the route line coordinates is easy. Here is a blog post that includes an example of how to get the route line and turn it into a SQLGeography: http://www.bing.com/blogs/site_blogs/b/maps/archive/2013/08/05/advance-spatial-queries-using-entity-framework-5.aspx

    http://rbrundritt.wordpress.com

    Thursday, October 24, 2013 9:02 AM
  • I've never come across the error you are having, but it's easy enough to work around. Simply create an SQL Geometry, use the MakeValid method on it, then convert this to an SQL Geography by passing the Well Known Binary of the SQL Geometry to a new instance of SQL Geography. This is actually something that you should do with any data that is not guaranteed to be OGC compliant.

    Also, I highly recommend reducing the resolution of the line using the Reduce method before doing any kind of buffering. This greatly improves performance.

    In general this whole process is very fast and any performance decrease will be minimal (milliseconds). This shouldn't be enough to cause any issue unless you are doing this for a massive number of routes, in which case I'd be interested in knowing more about what you are doing with Bing Maps.

    As for your other comments, it's worth noting that the routing data was only meant to be displayed on Bing Maps and not used in SQL. Note it is against the terms of use of Bing Maps to store route data. This is due to restrictions set by the data provider. The process of using Bing Maps to generate a LineString in SQL and buffering it is one that I come across a lot and this is the first time I've ever ran into anyone who had an issue with doing this.


    http://rbrundritt.wordpress.com

    Thursday, October 24, 2013 4:39 PM

All replies

  • I have done this many times. The best approach is to calculate the route on the server side rather than in the client app. This way you won't need to send the route data to the server from your app. Using the Bing Maps REST services to get the route line coordinates is easy. Here is a blog post that includes an example of how to get the route line and turn it into a SQLGeography: http://www.bing.com/blogs/site_blogs/b/maps/archive/2013/08/05/advance-spatial-queries-using-entity-framework-5.aspx

    http://rbrundritt.wordpress.com

    Thursday, October 24, 2013 9:02 AM
  • Thanks for reply.

    I'm using this solution for a few months but I think it's not a good solution for this reason :

    • the Rest api can return road with error for the conversion to SqlGeography instance. If you have at least two occurence of the same point in the Road, the sqlgeography is not valid !!! I'm obliged to make a routine to identify if my road is in this case in order to remove the multiple occurence of the same point. This loop can be very slow if you have a road with several thousand points.
    • If you calculate an itineray with multiple waypoint, the case above often appears.
    • With my corrective method above, if the road start for the point A, go to the point B, and finish with the point A, almost allt the points are double and my method removes almost all points.
    • In order to correct this last problem, I make a routine which split the routepath in many routepath, much as there leg. Why Bing don't give the route path for each legs??? In addition, the coordinates of the endpoint of leg is not exactly on the routepath !!! Very hard to split the road !!!

    So, my code works fine but I must make a lot of verification and routine (who decrease performance) in order to be sure to have a correct sqlGeography instance after calculate my route !!!

    Microsoft make bing map, Microsoft make sqlServer geography datatype, but microsoft don't make the interoperability. It's more easy to work with SqlServer and osm than work with sqlserver and Bing Map!!!!!!!

    WHY???

    I think that like in a lot of subject (Silverlight, VFP, setup project not in VS 2012, the list is long.........), Micorosoft is shooting himself.

    Thursday, October 24, 2013 12:18 PM
  • I've never come across the error you are having, but it's easy enough to work around. Simply create an SQL Geometry, use the MakeValid method on it, then convert this to an SQL Geography by passing the Well Known Binary of the SQL Geometry to a new instance of SQL Geography. This is actually something that you should do with any data that is not guaranteed to be OGC compliant.

    Also, I highly recommend reducing the resolution of the line using the Reduce method before doing any kind of buffering. This greatly improves performance.

    In general this whole process is very fast and any performance decrease will be minimal (milliseconds). This shouldn't be enough to cause any issue unless you are doing this for a massive number of routes, in which case I'd be interested in knowing more about what you are doing with Bing Maps.

    As for your other comments, it's worth noting that the routing data was only meant to be displayed on Bing Maps and not used in SQL. Note it is against the terms of use of Bing Maps to store route data. This is due to restrictions set by the data provider. The process of using Bing Maps to generate a LineString in SQL and buffering it is one that I come across a lot and this is the first time I've ever ran into anyone who had an issue with doing this.


    http://rbrundritt.wordpress.com

    Thursday, October 24, 2013 4:39 PM
  • Re,

    I'll try the solution with sqlGeometry before convert to geography tomorrow ! Thank you for the tip!

    About the problem of split road, the Ajax api seem's to be able to give the routepath of each legs against the rest Api.

    About my use of bing map, in France, a new tax call "EcoTaxe" will come on 01/01/2013. All truck who take some point on some road must paid this tax. I have a table which contains the taxed point. I use bing map in order to calculate some itinerary, convert into sqlgeography , and make a sql query for know the price of the future tax.

    I don't store any data from bing and i respect the terms of use of bing maps ! My french reseller agree with my usage and I have a discussion with him in order to know when I have to paid. If my usage become  a not free usage (over 125000 transactions...), I'll take an enterprise license with know user.

    But I work also with osm. Their data are not sure but open (I can store it and make my own itinary) and grow up (with some contributors like me and my consummers vehicle !!!). Their data contains truck restrictions (weight, height...). The inconvenient is the infrastructure I need to make my own GIS (big database, server with a lot of memory...). But with the osm solution, I've no restriction and I work directly with sqlserver datatyppes ! it is unfortunate that Microsoft don't transmit the sqldata (it's very unnecessary because we can transform and store it (not my case!))!This can change my choice about geography processing in my app !!!

    Thank you for reply and sorry for my poor english. I hope you understand my idea.

    P.S. : I already use reduce before query... Why routepath is not conform to the OGC ??????? This is the same reason that IE don't respect the w3C????



    • Edited by bobertin Thursday, October 24, 2013 6:52 PM
    Thursday, October 24, 2013 6:22 PM