12 Raster processing

 

This chapter covers

  • Loading raster data
  • Spatial aggregate raster functions
  • Accessing pixel values and isolating bands
  • Retiling rasters
  • Using geometries to clip rasters
  • Raster statistical functions
  • Map algebra functions

One of the most powerful aspects of PostGIS is its ability to use geometry and rasters in tandem. This chapter focuses on the use of raster aggregate functions, functions to manipulate rasters down to the pixel level, and functions for deriving additional rasters and geometries. You’ll also learn about built-in summary statistic functions that you can use to explore the distribution of pixel values. You’ll learn how to use geometry to isolate pixel values of interest.

For many of the examples in this chapter, we used climate data from WorldClim (www.worldclim.org/data/worldclim21.html). We downloaded elevation, precipitation, and average temperature raster monthly data divided into 10 minute degree intervals and covering 1970–2000. The data came packaged as .tif files. Elevation is in meters, precipitation in millimeters, and temperature in degrees Celsius. We also made an occasional excursion to Kauai, Hawaii, for which we downloaded elevation data (http://gis.ess.washington.edu/data/raster/tenmeter/hawaii/index.html).

You can download all the code and some of the data for this chapter at www.postgis.us/chapter_12_edition_3. The WorldClim data has redistribution restrictions, so it’s not included in the download.

12.1 Loading and preparing raster data

12.2 Forming larger rasters using spatial aggregate functions

12.2.1 Reconstituting tiled files

12.2.2 Carving out areas of interest using clipping and unioning

12.2.3 Using specific expression types with ST_Union

12.3 Working with bands

12.3.1 Using ST_AddBand to form multiband rasters from single-band rasters

12.3.2 Using ST_Band to process a subset of bands

12.4 Tiling rasters

12.5 Raster and geometry intersections