Accessing Geospatial Data with PyShp, Shapely and Fiona

by | Oct 29, 2018

The new 1.5 version of the ArcGIS API for Python integrates the PyShp, Shapely and Fiona packages, so that vector data from other libraries can be accessed through the API as well. Let’s have a look at the these three Python libraries and how they are used within the latest version of the API for Python.

Users familiar with open source spatial Python libraries will be very happy to know that the Esri API for Python 1.5 version can read spatial data from multiple sources, thanks to the integration of these three Python libraries for using shapefile data. This makes it easier to use the API and work with geospatial data regardless of the platform used.

Shapely

This Python library is used for manipulation and analysis of geometric objects. It can be described as a more Pythonic version of the OGR library, that has mainly the same functions and classes as Shapely. OGR is part of GDAL, a popular open source library that deals with vector data. It is very powerful and is used by many geospatial applications. However, OGR was written in C++ and is available in Python through a set of Python bindings: using it will feel strange, as it doesn’t follow the Python syntax rules.

Shapely uses its own geometry types that are stored as classes in the library’s geometry module: the available classes are points, multi points, line strings, multiline strings, linear rings, polygons, multi polygons and geometry collections. Using Shapely, you can manipulate and analyze the geometries of these different classes using geometry functions such as “buffer”, “intersects” and “contains”.

With regards to the Esri API for Python, consulting the Documentation shows that a large number of properties and functions from the Shapely library are valid on the API’s new data object called Spatially Enabled DataFrame (SEDF). When creating a spatial object from a SEDF, the API will first leverage the arcpy geometry engine, then shapely.

Fiona

This Python library can be used for reading and writing spatial vector data formats. It is often used in combination with Shapely, so that Fiona is used for creating the input and output, while Shapely does the “data wrangling” part in between. Fiona uses two markup languages worth knowing: WKT and WKB, Well-known Text and Well-known Binary. These formats allow for interchanging geographical objects between different GIS programs. With regards to the Esri Python API for Python, both are valid properties on Spatially Enabled DataFrame objects.

pyshp

This full name of this Python library is Python Shapefile Library. Its use is quite limited: it is meant for reading and writing shapefiles. The Esri API for Python uses it to read and write shapefiles when it cannot find a local installation of the arcpy site package.

Categories

Recent Posts

Eric van Rees
Eric van Rees is a freelance writer and editor. His specialty is GIS technology. He has more than eight years of proven expertise in editing, writing and interviewing as editor and editor-in-chief for the international geospatial publication GeoInformatics, as well as GIS Magazine and CAD Magazine, both published in Dutch. Currently, he writes about geospatial technology for various clients, publications and blogs.

Sign up for our weekly newsletter
to receive content like this in your email box.