chapter seven

7 Raster functions

 

This chapter covers:

  • Constructor functions
  • Output functions
  • Raster band and pixel accessors and setters
  • Georeferencing functions
  • Reclassing functions
  • Polygonizing functions

The raster type is different in makeup from the geometry type covered in chapter 6. Geometries model an object as a set of linear equations, whereas rasters model an object as a tapestry of cells. In PostGIS, you’ll find the two types working together, leveraging each other’s strengths. For example, you can output a geometry in a raster file format such as PNG. You can also clip raster images with vector boundaries. We’ll touch on raster processing in this chapter, but we’ll leave the more thorough treatment for chapter 12, where we’ll demonstrate advanced raster-processing functions, such as raster aggregate functions, map algebra functions, and set-returning functions.

7.1  Raster terminology

7.2  Raster constructors

7.2.1  Converting geometries to rasters with ST_AsRaster

7.2.2  Loading rasters with raster2pgsql

7.2.3  Constructing rasters from scratch: ST_MakeEmptyRaster and ST_AddBand

7.2.4  Setting pixels: ST_SetValue and ST_SetValues

7.2.5  Creating rasters from other rasters

7.2.6  Converting other raster formats with ST_FromGDALRaster

7.3  Raster output functions

7.3.1  ST_AsPNG, ST_AsJPEG, and ST_AsTiff

7.3.2  Output using ST_AsGDALRaster

7.3.3  Using psql to export rasters

7.4  Raster accessors and setters

7.4.1  Basic raster metadata properties

7.4.2  Pixel statistics

7.4.3  Pixel value accessors

7.4.4  Band metadata setters

7.5  Georeferencing functions

7.5.1  Metadata setters