Database Reference
In-Depth Information
Converting
between
rasters
and
geometries
Inthelastrecipe,weusedthegeometriestofilterandcliprastersonlytotheareasof
interest.Thefunctions ST_Clip() and ST_Intersects() implicitlyconvertedthe
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 providesone 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'sadaptpartofthequeryusedinthelastrecipetofindouttheaverageminimum
temperature in San Francisco. We replace ST_SummaryStats() with
ST_DumpAsPolygons() and then return the geometries as WKT .
WITH geoms AS (
SELECT
ST_DumpAsPolygons(
ST_Union(
ST_Clip(prism.rast, 2,
ST_Transform(sf.geom, 4322), TRUE)
),
1
Search WWH ::




Custom Search