Fiona
The Fiona library provides a simple Python API around the OGR library for data access and nothing more. This approach makes it easy to use and is less verbose than OGR while using Python. Fiona outputs GeoJSON by default. You can find a wheel file for Fiona at http://www.lfd.uci.edu/~gohlke/pythonlibs/#fiona.
As an example, we'll use the GIS_CensusTract_poly.shp file from the dbfpy example seen earlier in this chapter.
First we'll import fiona and Python's pprint module to format the output. Then, we'll open the shapefile and check its driver type:
>>> import fiona
>>> import pprint
>>> f = fiona.open("GIS_CensusTract_poly.shp")
>>> f.driver
ESRI ShapefileNext, we'll check its coordinate reference system and get the data bounding box, as shown here:
>>> f.crs
{'init': 'epsg:4269'}
>>> f.bounds
(-89.8744162216216, 30.161122135135138, -89.1383837783784, 30.661213864864862)Now, we'll view the data schema as geojson and format it using...