Friday, March 23, 2012

Generating great circles from a common origin with Python

Following Claudia Engel's blog post: Great circles on a recentered worldmap, in ggplot, in which a solution in R is provided, I was asked to build an alternative solution in Python. I used the following components:

Python 2.7
pandas 0.7.0.dev
pyproj 1.9.0



The CSV data files with airport locations and flight information from Beijing (PEK) airport are airports_new.csv and PEK.csv, respectively. These data were derived from openflights.org.

The KML generated is easily visualized in Google Earth:


As expected, the vector layer is displayed in other GIS desktop clients unpleasantly. See for instance how it looks in QGIS:


I decided not to alter the coordinates and recenter the world map around Beijing and fix the split polygons problem. Google Earth does the trick.

Produce the output KML file from command line (UNIX) like so:
$ python great_circles.py > out.kml

Here is the compressed KML output file.


Alternative partial implementations


Shown next is how I use pyKML (0.1.0) to generate 'almost' the same output above:

No comments:

Post a Comment