Reputation: 415
I want to detect if given Geo coordinates fall into the route I will be tracing. I am using shapely for this but that doesn't seems to be working correcly with Geo Coordinates. Can you please explain what am I doing wrong here
Using snap_to_road google maps API I snap the route to get multiple GPS points along the route, then I create the LineString(coordinates) from it and used LineString.contains method to check if given point falls in the line
>>> from shapely.geometry import *
>>> coords = [(18.541658213425041,73.802487036668737),(18.541715999999997,73.8024635),(18.5417578,73.8024447),(18.5417578,73.8024447),(18.5417748,73.802437),(18.541841700000003,73.8023838),(18.541933099999998,73.8022613),(18.542033699999998,73.8021515),(18.542150000000003,73.802104)]
>>> line = LineString(coords)
>>> line.contains(Point(18.541933099999998,73.8022613))
True
>>> line.contains(Point(18.542077799999994,73.8021211))
False
Code to get multiple points across the route:
import urllib,json,requests
request = "https://roads.googleapis.com/v1/snapToRoads?path=18.5416582,73.802487|18.5462013,73.8025098|18.5536253,73.80331540000002\
&interpolate=true&key=<API KEY>"
response = urllib.urlopen(request).read()
print response
As per google maps this (18.542077799999994,73.8021211) point is a part of route these co-ordinates are following. Then why does shapely failed to detect it ? Does it has to do something with 2D and 3D geometry.
Edit: Following two sites will help you to measure buffer value in meteres
http://www.longitudestore.com/how-big-is-one-gps-degree.html https://www.rapidtables.com/convert/number/degrees-to-degrees-minutes-seconds.html
Upvotes: 1
Views: 445
Reputation: 1393
Use buffer
method to dialate little bit. Increase the number 0.01
if you can allow more tolerance.
line.buffer(0.01).contains(Point(18.541933099999998,73.8022613))
Upvotes: 1