Geospatial Open Source Python Libraries

This chapter lists open-source packages for geospatial file manipulation with Python. The necessary packages are already installed flusstools. The following sections provide explanations of relevant and optional packages for this ebook and how those can be installed.

arcpy / ArcGIS

The proprietary license-requiring arcpy package is described in the chapter on The Commercial arcpy Library.

gdal (Includes ogr and osr)

gdal for raster data handling, ogr for vector data handling, and osr for spatial referencing of the OSGeo Project stem from the GDAL/OGR project, which is part of the Open Source Geospatial Foundation (OSGeo - the developers of QGIS). gdal provides many methods to convert geospatial data (file types, projections, derive geometries), where gdal itself handles Gridded Cell (Raster) Data and its ogr module handles Vector Data. The tutorials in this ebook depend on gdal and ogr (including osr for spatial referencing), which is why it is important to get the installation of gdal right.

Linux users may follow the instructions for installing gdal and flusstools with pip and venv (Linux Preference).

Windows users preferably install gdal and flusstools in a conda env (Windows Preference)ironment through Anaconda.

geojson

The geojson library is the most direct option for handling GeoJSON data and is also already installed along with flusstools.

To install geojson, open Terminal and type:

pip install geojson

To install geojson for Python Anaconda, open Anaconda Prompt and type:

conda install -c conda-forge geojson

Descartes Labs

Even though of proprietary origin, the descarteslabs package (developed and maintained by Descartes Labs comes with many open-sourced functions. Moreover, Descartes Labs hosts the showcase platform GeoVisual Search with juicy illustrations of artificial intelligence (AI) applications in geoscience. Note that descarteslabs is not installed along with flusstools.

To install descarteslabs, open Terminal and type:

pip install descarteslabs

To install descarteslabs for Python, open Anaconda Prompt and type:

conda install -c conda-forge descartes

If the installation fails, try the following:

conda install shapely
pip install descarteslabs

Python Imaging Library (PIL) / pillow

Processing images with Python is enabled with the Python Imaging Library (PIL). PIL supports many image file formats and has efficient graphics processing capabilities. The pillow library is a user-friendly PIL fork and provides Image* modules (e.g., Image, ImageDraw, ImageMath, and many more). If flusstools is installed, no further action is required for working with the PIL/pillow-related contents of this ebook.

Note that the conda base environment includes PIL (test with import PIL), which needs to be uninstalled before installing pillow. For installing PIL/pillow, refer to https://pillow.readthedocs.io.

shapely

A preferable and very well documented package for Shapefile handling is shapely. shapely is already installed along with flusstools.

To install shapely, open Terminal and type:

pip install Shapely

To install shapely for Python Anaconda, open Anaconda Prompt and type:

conda install -c conda-forge shapely

pyshp

Another Shapefile handling package pyshp, which provides pure Python code (rather than wrappers), which simplifies direct dealing with shapefiles in Python. pyshp is already installed along with flusstools.

To install pyshp, open Terminal and type:

pip install pyshp

To install pyshp for Python Anaconda, open Anaconda Prompt and type:

conda install -c conda-forge pyshp

Other packages

Besides the above-mentioned packages, there are other useful libraries for geospatial analyses in Python . Packages in bold font are installed along with flusstools.

  • alphashape creates bounding polygons containing a set of points.

  • django as a geographic web frame and for database connections.

  • geopandas enables the application of Pandas data frame operations to geospatial datasets.

  • NetworkX for network analyses such as finding a least-cost / shortest path between two points.

  • owslib to connect with Open Geospatial Consortium (OGC) web services.

  • postgresql for SQL database connections.

  • rasterio for processing raster data as NumPy arrays.

  • rasterstats produces zonal statistics of rasters and can interact with GeoJSON files.

  • sckit-image for machine learning applied to georeferenced images.