Just wrapped up a new library called PyGeoj that makes it a breeze to read and write geojson as files. By treating geojson as an actual fileformat instead of just as a set of formatting rules, the aim was that PyGeoj should make it just as easy to deal with .geojson files as with .shp files — sort of like the PyShp for Geojson data.
Since the arrival of the Geojson format, there has been an increasing ability to send and receive geometry types between different libraries when doing Python GIS programming. As useful as this is, it seems to me that this has made geojson more of an inter-library communication language than an actual file-format (like the shapefile). Using the built-in json library and playing with the geojson dictionary directly is one option, using the python-geojson library is another, but both require a fairly intimate knowledge of the format specification (ie more suitable for developers than actual end-users).
PyGeoj focuses on only a few basic classes, and hopefully intuitive attributes and methods. As such, loading a file can be done with:
testfile = pygeoj.load(“testfile.geojson”)
Resulting in a file instance whose file-information like “crs” or “bbox” and features can be accessed, edited, and eventually saved:
for feature in testfile:
Although geojson is generally slower and more memory consuming than the shapefile format, PyGeoj will hopefully encourage use of the geojson format for everyday-tasks or sending data to other libraries across “long distances” (eg online).