Geospatial support in wq.io

wq version: 1.0 1.1 1.2
Docs > wq.io: Dataset IO

Geospatial support in wq.io


wq.io includes a gis submodule with a number of extensions for working with geospatial data. This submodule requires Fiona, Shapely, and GeoPandas, which are not installed with wq.io by default. wq.io.gis provides a Fiona-powered loader and parser, as well as three Shapely and GeoPandas-powered mapper classes. These are combined with a GIS-aware BaseIO extension to provide a set of three pre-mixed base classes, described below.

To leverage all of these features:

pip install wq.io
pip install geopandas


The GisIO class (and the corresponding GisMapper mixin) provide an API similar to TupleMapper, but with a geometry field on each row containing the GeoJSON-like objects returned from Fiona.

from wq.io.gis import GisIO
data = GisIO(filename='sites.shp')
for id, site in data.items():
    print id, site.name, site.geometry['type']

Note that all of the gis IO classes assume a key_field of "id" and will behave like a dict (See BaseIO).


The ShapeIO class (and corresponding ShapeMapper mixin) replaces the GeoJSON-like geometry attribute with a Shapely geometry object for convenient manipulation and computation.

from wq.io.gis import ShapeIO
data = ShapeIO(filename='sites.shp')
for id, site in data.items():
    print id, site.name, site.geometry.area


The WktIO class (and corresponding WktMapper mixin) replaces the Shapely geometry attribute with a WKT string to simplify use with other libraries.

from wq.io.gis import WktIO
data = WktIO(filename='sites.shp')
for id, site in data.items():
    OrmModel.objects.create(name=site.name, geometry=site.geometry)


Like all wq.io classes, the gis IO classes provide an as_dataframe() function for Pandas-powered analysis.

from wq.io.gis import ShapeIO
data = ShapeIO(filename='sites.shp')
df = data.as_dataframe()

Syncing gis IO classes

All gis IO classes support the sync() operation (see BaseIO). Additional care is taken to ensure the Shapely metadata (other than the driver) is synced together with the data.

source = ShapeIO(filename="source.shp")
dest = ShapeIO(filename="dest.geojson")