O'Reilly logo

PostGIS Cookbook by Bborie Park, Stephen Vincent Mather, Thomas J. Kraft, Paolo Corti

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Converting between rasters and geometries

In the last recipe, we used the geometries to filter and clip rasters only to the areas of interest. The functions ST_Clip() and ST_Intersects() implicitly converted the geometry before relating it to the raster.

PostGIS provides several functions for converting rasters to geometries. Depending on the function, a pixel can be returned as an area or a point.

PostGIS provides one function for converting geometries to rasters.

Getting ready

In this recipe, we will convert rasters to geometries and geometries to rasters. We will use the ST_DumpAsPolygons() and ST_PixelsAsPolygons() functions to convert rasters to geometries. We will then convert geometries to rasters using ST_AsRaster().

How to do it...

Let's adapt ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required