• Presentación Smart City y Geolocalización: Héctor García
  • Sample Page
  • ES
  • EN
  • Avda. de Grecia 8. 41012 Sevilla, España
  • |
  • www.geographica.gs

Computing the shortest path on an ellipsoid with Python

Geodesic lines & GIS

Posted at 11/06/2015 by Cayetano Benavent

A geodesic (aka geodesic line) is the shortest path between two points located on a given surface. In the world of cartography and geodesy, figure out the shortest path between two locations on an ellipsoid of revolution involves compute a geodesic line joining them (see more in Wikipedia). Consider the Earth as a sphere makes calculations easier, being the shortest path a great circle arc between the points (more on Wikipedia).

For some time, one of the main open source libraries from geo ecosystem, Proj.4, has been introducing major changes in its algorithms for geodetic computations. Specifically, since version 4.9 has been ported to C (inside Proj.4) part of the C ++ library GeographicLib written by Charles Karney (more on algorithms of C. Karney).

Until version 4.8 this library had been using Paul D. Thomas algorithms for Geodesy. The heavy use I make of this library every day has led me to do some testings on geodesic distance calculations. In this link you can access a benchmark I did with several libraries to calculate the geodesic distance between different locations, knowing the coordinates of these locations (which involves figure out the inverse geodetic problem): https://github.com/cayetanobv/GeodeticMusings

Thereafter, and in support of other tasks I was undertaking, I developed a small application which solves inverse geodetic problem based on the above algorithms and computes a geodesic line between start and end points in GIS format directly (Shapefile and/or GeoJSON): GeodesicLinesToGIS.

Is important to highlight that the program efficiently solves the problem of geodesic lines crossing antimeridian (180º) when generating geometries in GIS format. This library is builded on top of three excellent libraries: Pyproj, Fiona and Shapely.

In the examples below you can see the difference between computed geodesic line (shortest path; green line), rhumb line (or loxodromic; red line) and straight line between two points (black dashed line). The maximum differences, as you can expect, occurring between Mercator projection (see Fig 1; loxodromic is a straight line) and Gnomonic projection (see Fig 2; geodesic is a straight line). The problem of geodesic lines crossing 180º is solved, as you can see in Fig 3 and Fig 4.

Fig 1. Mercator Projection: Geodesic lines
Fig 1. Mercator Projection.
Geodesic lines
Fig 2. Gnomonic Projection (centered on 50ºW y 60ºN).
Fig 3. Geodesic lines crossing 180º, Mercator Projection.
Fig 3. Geodesic lines crossing 180º, Mercator Projection.
Fig 4. Geodesic lines crossing 180º, Mercator Projection (Centered on 150ºE).
Fig 4. Geodesic lines crossing 180º, Mercator Projection (Centered on 150ºE).

You can install this package from PYPI (Python Package Index):

https://pypi.python.org/pypi/GeodesicLinesToGIS

Of course, sources are on GiHub:

https://github.com/GeographicaGS/GeodesicLinesToGIS

See you soon!

GISOpen sourcePython
GEO_blog_cayetano
Posted at 11/06/2015 by
 Cayetano Benavent
GIS Analyst
SHARE
Posted in: GIS, Open source, Python | Tagged: Geodesic lines, gis
← Towards a tiles engine based on Spark
Carto & Geographica: the beginning of a beautiful friendship →

© 2023 Geographica. Todos los derechos reservados.

  • English
  • Español