Friday, March 30, 2012

Great circle flights from Beijing, arcpy version

In the previous post, we found a pure Python solution to generating great circles from a common point, specifically from Beijing airports to all other airports in the world that maintain commercial flight routes from it. This situation is modeled by finding geodesic arcs, great circles from point to point in the spheroid.


In this post we present a solution implemented only with arcpy (ESRI's ArcGIS 10.0 Python geoprocessing package):



Here you can download the complete script with data. Change the root of your workspace from "C:\pythonGIS" accordingly and unzip the files in the new root defined.

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: