Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement suggestion: uses of geodesic distance calculation #3

Open
guidoeco opened this issue Jan 21, 2016 · 0 comments
Open

Enhancement suggestion: uses of geodesic distance calculation #3

guidoeco opened this issue Jan 21, 2016 · 0 comments

Comments

@guidoeco
Copy link

As an enhancement, the following patch uses the geopy library Vincenty (aliased as geopy.distance.distance) to calculate the geodesic distance between two points. The patch does introduce a dependency on the geopy library, but when tested I found it reduced the number files needed for caching and the time to run by 20-30%. (YMMV.)

@@ -28,6 +28,8 @@
import sys
import math
from loadOsm import LoadOsm
+from geopy import Point
+import geopy.distance

class Router(object):
def init(self, data):
@@ -39,10 +41,9 @@ class Router(object):
lat2 = self.data.rnodes[n2][0]
lon2 = self.data.rnodes[n2][1]
# TODO: projection issues

  • dlat = lat2 - lat1
  • dlon = lon2 - lon1
  • dist2 = dlat * dlat + dlon * dlon
  • dist = math.sqrt(dist2)
  • p1 = Point(lat1, lon1)
  • p2 = Point(lat2, lon2)
  • dist = geopy.distance.distance(p1,p2).km
    return(dist)

def doRoute(self,start,end):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant