Python Tools for Great Circle Distance and Line Creation

distancegreat circlepolyline-creationpython

I need to use Python to create a great circle distance — both a number, and preferably some kind of 'curve' that I can use to draw in a client-side map. I don't care about the format of the curve — be it WKT, or a set of pairs of coordinates — but just want to get the data out.

What tools are there out there? What should I use?

Best Answer

pyproj has the Geod.npts function that will return an array of points along the path. Note that it doesn't include the terminal points in the array, so you need to take them into account:

import pyproj
# calculate distance between points
g = pyproj.Geod(ellps='WGS84')
(az12, az21, dist) = g.inv(startlong, startlat, endlong, endlat)

# calculate line string along path with segments <= 1 km
lonlats = g.npts(startlong, startlat, endlong, endlat,
                 1 + int(dist / 1000))

# npts doesn't include start/end points, so prepend/append them
lonlats.insert(0, (startlong, startlat))
lonlats.append((endlong, endlat))