Database Reference
In-Depth Information
Executing DEM operations
PostGIS comeswith severalfunctions foruseondigital elevation model(DEM)ras-
terstosolveterrain-relatedproblems.Thoughtheseproblemshavehistoricallybeen
in the hydrology domain, they can now be found elsewhere, for example, finding
the most fuel-efficient route from point A to point B or determining the best location
on a roof for a solar panel. PostGIS 2.0 introduced
ST_Slope()
,
ST_Aspect()
,
and
ST_HillShade()
while PostGIS 2.1 added the new functions
ST_TRI()
,
ST_TPI()
, and
ST_Roughness()
, and new variants of existing elevation functions.
Getting ready
WewillusetheSRTMraster,loadedas100x100tiles,inthischapter'sfirstrecipe.
Withit,wewillgenerateslopeandhillshaderastersusingSanFranciscoasourarea
of interest.
Thetwoqueriesbelowusevariantsof
ST_Slope()
and
ST_HillShade()
thatare
onlyavailableinPostGIS2.1orhigherversions.Thenewvariantspermitthespecific-
ation of a custom extent to constrain the processing area of the input raster.
How to do it...
Let's generate a slope raster from a subset of our SRTM raster tiles using
ST_Slope()
.Asloperastercomputestherateofelevationchangefromonepixelto
a neighboring pixel.
WITH r AS ( -- union of filtered tiles
SELECT
ST_Transform(ST_Union(srtm.rast), 3310) AS rast
FROM srtm
JOIN sfpoly sf
ON
ST_DWithin(ST_Transform(srtm.rast::geometry, 3
310), ST_Transform(sf.geom, 3310), 1000)
), cx AS ( -- custom extent