Geospatial Open Source Python Libraries#

This section lists open-source packages for geospatial file manipulation with Python. The necessary packages are already installed flusstools. In addition, the following paragraphs 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 briefly described in the chapter on the commercial arcpy library. However, this eBook strongly recommends using the open-source libraries, such as gdal.

OSGeo and GDAL Including ogr and osr#

The gdal library for raster data handling comes along with ogr for vector data handling, and osr for geospatial referencing. GDAL and OGR are managed and developed by the OSGeo Project, which is part of the Open Source Geospatial Foundation - the developers of QGIS.

The tutorials in this eBook build on gdal and ogr (including osr for spatial referencing), which is why it is important to get the installation of GDAL right:

Select your platform for more specific installation instructions:

GDAL requires sudo-installation. Find more details in the Python installation instructions of this eBook.

To install GDAL for Python through Anaconda Prompt enter:

conda install -c conda-forge gdal

Import GDAL, ogr, and osr from OSGeo

Importing gdal, ogr, and osr directly (e.g., import gdal) is deprecated since GDAL v3. Therefore, gdal, ogr, and osr must be imported from osgeo:

from osgeo import gdal
from osgeo import osr
from osgeo import ogr

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 library (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#

pyshp is another shapefile handling package, which builds on pure Python code (rather than wrappers) to simplify 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 with Python (Packages in bold red 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.