Python and GeoJSON
GeoJSON is a browser-era alternative to the good old WKT format. It's not that
{"type": "LineString", "coordinates": [[0.0, 0.0], [1.0, 0.0]]}
is
easier to parse than or technically superior to LINESTRING (0.0 0.0, 1.0
0.0)
, but that we can now represent geometric objects using a more general
and widely used format: uniform use of JSON instead of WKT for geometry and
some other format for non-geometric data.
On Seth G's geographika blog there's a fine demo of fetching GeoJSON from a web service and plotting it with matplotlib and descartes. Descartes deals in GeoJSON-like Python objects and so he could in fact keep the data in that form from start to finish.
This morning I found an email pointing out ArcPy's support for data interchange using the same kind of GeoJSON-like Python objects: AsShape().
import arcpy gjPolygon = { "type": "Polygon", "coordinates": [[[10.0, 0.0], [20.0, 0.0], [20.0, 10.0], [10.0, 10.0], [10.0, 0.0]]] } polygon = arcpy.AsShape(gjPolygon)
Is GeoJSON (as a dict
) a new lingua franca for Python GIS? Will wider use
mean that we'll finally have to do something about the GeoJSON specification's
defficiencies at the date line and poles?
Comments
Re: Python and GeoJSON
Author: Howard Butler
WKT says nothing about datelines and poles. Additionally, there's nothing now from preventing a user to properly set and interpret their coordinate system and interpret the poles/datelines as they need right now.
Re: Python and GeoJSON
Author: Seth
I started using JSON because of MapFish and the ExtJS JavaScript Framework to pass tabular data between services and web applications, so GeoJSON seemed the obvious choice especially when OpenLayers has GeoJSON built in.
The main competitor to GeoJSON seems to be JSON..CloudMade serve out OpenStreetMap data in both formats - but with differing coordinate orders.
Are there any more GeoJSON services apart from those listed at http://wiki.geojson.org/Users ?
Re: Python and GeoJSON
Author: Sean
More services? Probably. As it is, Twitter is a service, not a server, and a big one (though with screwy coordinates). If all new GeoServer instances provide GeoJSON, that's a lot of services. GeoJSON is useful as a wire format, but it's also useful (IMO) as structure for passing data in Python.
GeoJSON is a bit geo-enterprisey: there are "geometries", "features", and "feature collections" all more or less in accord with the OGC feature model. OpenStreetMap has a different, graph-centric model and a different format makes sense.
Howard: I agree that the format doesn't get in the way of correct implementations.