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
osr for spatial referencing), which is why it is important to get the installation of
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 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.
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
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.
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 in Python .
Packages in bold font are installed along with flusstools.
alphashapecreates bounding polygons containing a set of points.
djangoas a geographic web frame and for database connections.
NetworkXfor network analyses such as finding a least-cost / shortest path between two points.
owslibto connect with Open Geospatial Consortium (OGC) web services.
postgresqlfor SQL database connections.
sckit-imagefor machine learning applied to georeferenced images.