Gary van der Merwe - 11 months ago 72

Python Question

If I have a line defined by a start and end coordinates, how do I get n equally spaced points on that line, taking the curvature of the earth into account?

I'm looking for an algorithm, and/or a python library that implements this.

Answer Source

Using geographiclib, a python implementation of GeographicLib, I was able to do this:

```
from geographiclib.geodesic import Geodesic
number_points = 10
gd = Geodesic.WGS84.Inverse(35, 0, 35, 90)
line = Geodesic.WGS84.Line(gd['lat1'], gd['lon1'], gd['azi1'])
for i in range(number_points + 1):
point = line.Position(gd['s12'] / number_points * i)
print((point['lat2'], point['lon2']))
```

output:

```
(35.0, -7.40353472481637e-21)
(38.29044006500327, 7.8252809205988445)
(41.01134777655358, 16.322054184499173)
(43.056180665524245, 25.451710440063902)
(44.328942450747135, 35.08494460239694)
(44.76147256654079, 45.00000000000001)
(44.328942450747135, 54.91505539760305)
(43.05618066552424, 64.54828955993611)
(41.01134777655356, 73.67794581550085)
(38.290440065003274, 82.17471907940114)
(34.99999999999999, 90.0
```