GDAL reference

From Wildsong
Jump to navigationJump to search

Clip or Extract

Geometric

If you want to clip a rectangle out of a larger raster, for example to remove the collar from a scanned map, you can use gdal_translate but only if the input raster is not in a spherical projection. (For example, if it's in WGS84 (EPSG 4326) this will work.)

If the data is not projected you can use a gdal_translate command with either projwin or srcwin specifying a window on the command line.

If it is projected it will fail.

Using a mask

This tutorial shows how to use a shapefile to clip a raster: http://linfiniti.com/2009/09/clipping-rasters-with-gdal-using-polygons/

I want to use the neatline from a GeoPDF to remove the collar from a USGS scanned map. To do this, I need to make a polygon in a shapefile from the points in the neatline.

Distance

gdal_proximity

Generalization

gdal_sieve

Raster polygons smaller than a provided threshold size (in pixels) and replaces replaces them with the pixel value of the largest neighbour polygon. The result can be written back to the existing raster band, or copied into a new file.

Map algebra

Data conversion

Raster colorspaces conversion

rgb2pct.py

pct2rgb.py

Raster to Raster

Use gdal_translate

Raster to Polygon

gdal_polygonize

Vector to Raster

gdal_rasterize

Data management

Projections

To reproject data, use gdalwarp

Mosaic

The gdal_merge command creates a single raster output from several inputs. It does this the old-fashioned way by copying pixels.

Build raster catalog

(Or, "what is a VRT")

In GDAL world this is called a VRT = Virtual Dataset (which in my mind would abbreviate to "VD" but no one asked me.)

To build one you can use gdalbuildvrt

I think it creates a small file referencing the members of the dataset, which can then be processed by GDAL commands that accept only one input file.

Surfaces

Contour

To build a vector contour layer from an elevation dataset, use gdal_contour

Raster surfaces

To generate raster surfaces from an elevation dataset, use gdaldem

The list of surfaces you can generate includes

  • hillshade
  • color relief
  • shaded relief
  • slope
  • aspect
  • terrain ruggedness index
  • topographic position index
  • roughness