Skip to main content

GIS command-line "gems" for Linux and macOS

· 6 min read
Alex G Rice
Geodata rambler and developer, aka guidorice

In this part two of Linux posts, we'll discover some Geographic Information Systems (GIS) command-line interface (CLI) "gems" which work on Linux, Unix, or macOS. This is by no means an exhaustive list, and the intent is just to illustrate how powerful and extensible the Linux development environment is for geodata wrangling...

In part one of this series, I shared my story of being a Linux user for 30 years. Now let's dive into some specific, useful GIS related commands.

GDAL

Geospatial Data Abstraction Library (GDAL) installs literally 30+ different raster utility programs, like gdalinfo, gdalwarp, gdal_translate, gdal_merge, gdal_polygonize and many more.

Do you have a GIS raster which you want to work with or convert? Begin with gdalinfo {filename} to inspect it's bands, CRS, resolution, and other metadata. GDAL supports dozens of raster drivers for just about any raster file format you can think of. Common use cases include:

  • reading metadata
  • converting formats
  • reprojecting
  • masking
  • merging
  • rasterization
  • vectorizing / polygonizing
  • building overviews
  • Virtual Raster Tiles (VRTs): a powerful feature for working with virtual datasets.

GDAL can also read directly from object storage (AWS S3), using it's Virtual File Systems drivers, for example:

$ gdalinfo /vsis3/sentinel-cogs/sentinel-s2-l2a-cogs/46/C/DB/2022/10/S2B_46CDB_20221003_0_L2A/B02.tif
Driver: GTiff/GeoTIFF
Files: /vsis3/sentinel-cogs/sentinel-s2-l2a-cogs/46/C/DB/2022/10/S2B_46CDB_20221003_0_L2A/B02.tif
Size is 10980, 10980
Coordinate System is:
PROJCRS["WGS 84 / UTM zone 46S",
...

OGR

OGR Simple Features Library (OGR) is included with GDAL, which is why they are often referred to as "GDAL/OGR". OGR installs several vector programs:

  • ogrinfo works just like gdalinfo, but for vector data.
  • ogr2ogr is indispensable for converting between vector formats as well as searching, filtering and transforming vector datasets.

OGR supports dozens of vector drivers for just about any vector file format imaginable.

PDAL

Point Data Abstraction Library (PDAL) is very much like GDAL, but PDAL is for translating and manipulating point cloud data, for example Lidar.

pdal --help

Jq

jq is a command-line JSON processor. Technically it's not a GIS-specific tool, however it is a lightweight and flexible command-line JSON processor. The GeoJSON format is common in GIS applications, especially in web applications with RESTful APIs, and GeoJSON is also the foundation for the SpatioTemporal Asset Catalog (STAC) specification. Typical usage includes:

  1. pretty-printing
  2. querying and filtering
  3. printing feature attributes
jq --help

Rasterio

Rasterio is a Python library that reads and writes geospatial raster datasets. It's built on top of GDAL and Numpy, and provides a Pythonic interface to GDAL's data model. Rasterio is a powerful tool for reading and writing raster data in Python.

Rasterio also installs a cli program, rio, which is similar in purpose to GDAL's command line programs but rio is simpler, friendlier, and has better support for Cloud Optimized Geotiff (COG). Here is a quick start to install rio:

python -m venv venv/
source venv/bin/activate
pip install rasterio
rio --help

Fiona

Fiona can read and write real-world data using multi-layered GIS formats, zipped and in-memory virtual file systems, from files on your hard drive or in cloud storage. This project includes Python modules and a command line interface (CLI). Fiona docs

Fiona also installs a cli program, fio. Here is a quick start to install fio:

python -m venv venv/
source venv/bin/activate
pip install fiona
fio --help

DuckDB

DuckDB is an in-process, analytical, portable database which supports geospatial formats and queries. I don't have experience with it (yet) but Mark Litwintschik recently wrote a blog post about Wyvern's Open Data feed of hyperspectral remote sensing imagery, where he uses duckdb as well as several other Linux cli tools.

duckdb --help

Docker one-liners 🐳

Install Docker Desktop (Mac, Win) or Docker Engine (Linux) and then you can run lightweight containers, as shown in the following examples:

TiTiler raster tiling

TiTiler, pronounced tee-tiler (ti is the diminutive version of the french petit which means small), is a set of Python modules that focus on creating FastAPI applications for dynamic tiling. A common use case is on-demand raster tiles from Cloud Optimized Geotiff (COG) hosted in S3 or other object storage.

docker run --name try-titiler \
--platform=linux/amd64 -p 8000:8000 --rm \
ghcr.io/developmentseed/titiler:latest \
uvicorn titiler.application.main:app --host 0.0.0.0 --port 8000 --workers 1

Then browse to http://localhost:8000 to start using TiTiler.

PostgreSQL with PostGIS

PostGIS extends the capabilities of the PostgreSQL relational database by adding support for storing, indexing, and querying geospatial data. Why fumble around with a download and a GUI installer, when you can just run one docker command! Remember to replace the password string ***** with a new password:

mkdir -p ~/pgdata
docker run --name try-postgis \
-p 5432:5432 --rm \
-e POSTGRES_PASSWORD=***** \
-e PGDATA=/var/lib/postgresql/data/pgdata \
-v ${HOME}/pgdata:/var/lib/postgresql/data \
postgis/postgis:17-3.5

Then connect to Postgres using psql, DBeaver, PgAdmin, or any Postgres SDK. The latest version tags for the docker image e.g. postgis:17-3.5 are available on GitHub.

QGIS as raster tile server

Do you have a QGIS project (.qgz file) with 42 map layers which you worked on for 18 months, and now you have to publish it to the web? 😅 No problem- QGIS Server can serve up raster tiles via open standards like WMTS, WMS, XYZ, TMS, WFS, or WCS.

  • XYZ format may be easiest for integration with the Mapbox, OpenLayers, and Leaflet web map packages.
  • QGIS Server can be slow, depending on the complexity of your map layers, so you will likely want to setup a caching layer such as Varnish, TileStache, or a cloud CDN.
docker run --name try-qgis-server \
-p 8080:80 --rm \
-v /path/to/your/project.qgz:/etc/qgisserver/project.qgz \
-e QGIS_PROJECT_FILE=/etc/qgisserver/project.qgz \
qgis/qgis-server:latest
note

Some additional setup may be needed

  1. If your QGIS project references data that isn't embedded in the QGZ file, you'll need to add volume mounts for those data directories as well.
  2. Some additional project and layer configuration may be needed. More info at QGIS Server docs.

Cloud-Native Geospatial (CNG)

Check out the Cloud-Optimized Geospatial Formats Guide for more useful recipes, formats, and programs.


🌎 Thanks for rambling! 👋🏼

edits
  • 2025-03-21 Update Docker commands for consistency and macOS usage.