GDAL

GDAL is a translator library for raster and vector geospatial data formats. There are API documentation for C and C++. There are Node.js bindings and Python bindings and a Python cookbook.

There are several great tools for the command line and API’s that you can use to wrangle your geodata. The example that we will be discussing is raster GeoTIFFs from the US Forest Service FSTopo Raster Gateway.

gdal-config

You can use gdal-config to obtain the GDAL version

gdal-config --version

or you can list the supported formats in your GDAL installation

gdal-config --formats

Learning with Mt Whitney

Since we are working straight from the command line, we can start by calling commands to fetch to our GeoTIFFs. We have examples for wget and curl. You can use the FSTopo Raster Gateway if you prefer, but you can also start with the page that shows FSTopos near Mt Whitney.

wget http://data.fs.usda.gov/geodata/rastergateway/data/36118/fstopo/363011815_Mount_Whitney_FSTopo.tif

# or

curl -O http://data.fs.usda.gov/geodata/rastergateway/data/36118/fstopo/363011815_Mount_Whitney_FSTopo.tif

gdalinfo

With gdalinfo you can obtain great metadata about your file

gdalinfo 363011815_Mount_Whitney_FSTopo.tif

# output gdalinfo in json
gdalinfo -json 363011815_Mount_Whitney_FSTopo.tif

# histogram of palette colors
gdalinfo -hist 363011815_Mount_Whitney_FSTopo.tif

gdal_translate

Translating our GeoTIFF to other formats is useful, so we can use gdal_translate to perform operations. One caveat is that when you translate out of GeoTIFF, then you lose all geospatial information.

gdal_translate -of PNG 363011815_Mount_Whitney_FSTopo.tif 363011815_Mount_Whitney_FSTopo.png

# or translate to JPEG
gdal_translate -of JPEG 363011815_Mount_Whitney_FSTopo.tif 363011815_Mount_Whitney_FSTopo.jpg
gdal_translate -of JPEG -expand rgb 363011815_Mount_Whitney_FSTopo.tif 363011815_Mount_Whitney_FSTopo.jpg

# or translate to WEBP
gdal_translate -of WEBP -expand rgb 363011815_Mount_Whitney_FSTopo.tif 363011815_Mount_Whitney_FSTopo.webp

# or translate to uncompressed TIFF
gdal_translate -of GTIFF -expand rgb 363011815_Mount_Whitney_FSTopo.tif 363011815_Mount_Whitney_FSTopo.TIFF

awesome

Links to other awesome stuff