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
Watch this section as a video on the @Hydro-Morphodynamics channel on YouTube.
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
osr for spatial referencing), which is why it is important to get the installation of
Select your platform for more specific installation instructions:
GDAL requires sudo-installation. Find more details in the Python installation instructions of this eBook.
GDAL for Python through Anaconda Prompt enter:
conda install -c conda-forge gdal
Import GDAL, ogr, and osr from OSGeo
osr directly (e.g.,
import gdal) is deprecated since GDAL v3. Therefore,
osr must be imported from
from osgeo import gdal from osgeo import osr from osgeo import ogr
geojson, open Terminal and type:
pip install geojson
geojson for Python Anaconda, open Anaconda Prompt and type:
conda install -c conda-forge geojson
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.
descarteslabs, open Terminal and type:
pip install descarteslabs
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.,
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, open Terminal and type:
pip install Shapely
shapely for Python Anaconda, open Anaconda Prompt and type:
conda install -c conda-forge shapely
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.
pyshp, open Terminal and type:
pip install pyshp
pyshp for Python Anaconda, open Anaconda Prompt and type:
conda install -c conda-forge pyshp
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):
alphashapecreates bounding polygons containing a set of points.
django as a geographic web frame and for database connections.
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.
sckit-imagefor machine learning applied to georeferenced images.