Skip to Content
PostGIS Cookbook - Second Edition
book

PostGIS Cookbook - Second Edition

by Stephen Vincent Mather, Pedro Wightman, Bborie Park, Thomas Kraft, Mayra Zurbarán, Paolo Corti
March 2018
Beginner to intermediate content levelBeginner to intermediate
584 pages
14h 31m
English
Packt Publishing
Content preview from PostGIS Cookbook - Second Edition

How to do it...

Let's generate a slope raster from a subset of our SRTM raster tiles using ST_Slope(). A slope raster computes the rate of elevation change from one pixel to a neighboring pixel:

WITH r AS ( -- union of filtered tiles 
  SELECT ST_Transform(ST_Union(srtm.rast), 3310) AS rast 
  FROM chp05.srtm 
  JOIN chp05.sfpoly sf ON ST_DWithin(ST_Transform(srtm.rast::geometry,  
     3310), ST_Transform(sf.geom, 3310), 1000)),  
  cx AS ( -- custom extent 
    SELECT ST_AsRaster(ST_Transform(sf.geom, 3310), r.rast) AS rast 
    FROM chp05.sfpoly sf CROSS JOIN r 
  ) 
  SELECT ST_Clip(ST_Slope(r.rast, 1, cx.rast), ST_Transform(sf.geom, 3310)) AS rast FROM r 
CROSS JOIN cx 
CROSS JOIN chp05.sfpoly sf; 

All spatial objects in this query are projected to California Albers (SRID ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PostgreSQL 13 Cookbook

PostgreSQL 13 Cookbook

Vallarapu Naga Avinash Kumar
PostgreSQL High Performance Cookbook

PostgreSQL High Performance Cookbook

Dinesh Kumar, Chitij Chauhan
Mastering PostGIS

Mastering PostGIS

Dominik Mikiewicz, Michal Mackiewicz, Tomasz Nycz

Publisher Resources

ISBN: 9781788299329Supplemental Content