Skip to content

Instantly share code, notes, and snippets.

Created May 27, 2012 16:24
Show Gist options
  • Save anonymous/2814958 to your computer and use it in GitHub Desktop.
Save anonymous/2814958 to your computer and use it in GitHub Desktop.
select
id,
sum(st_area((gval).geom)
/ 10000) as total_area_ha,
round( min((gval).val)) as min_slope,
round( sum((gval).val * st_area((gval).geom))
/ st_area(st_collect((gval).geom))
) as avg_slope_sqm,
round( max((gval).val)) as max_slope
from (
select st_intersection(rast,1,db.the_geom) as gval,
db.the_geom,
db.gid as id
from slope2020
inner join
(select gid,the_geom
from (select the_geom from development bounds as ga, the_geom from rivers_roads7 as gb st_difference()as la
--where target_use = 'Golf Area', 'Village C'
) as db
on
st_intersects(rast,db.the_geom)
) as foo
-- Here's the new line that lets you constrain the results to below a specified slope:
where (gval).val < 16
-- End of new line.
group by id, foo.the_geom;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment