SRTM raster query for elevation give lat / lng

111 views
Skip to first unread message

Greg Flanagan

unread,
Oct 29, 2014, 4:30:21 PM10/29/14
to postgi...@googlegroups.com
I'm new to PostGIS so hopefully this isn't a stupid question. 

I'm using PostGIS 2.1 and loading it with SRTM rasters for the entire US using:   raster2pgsql -s 4236 -I -C -M *.hgt -F public.elevation | psql -d srtm

I'm not tiling it (eg. -t 100x100) so the tiles are 1200x1200. I want to be able to query the dataset to get an elevation given a latitude / longitude. I've figured out how to do it but it queries all of the rasters instead of just the one that contains the the point. This is what I have:

SELECT ST_Value(rast, ST_Transform(ST_SetSRID(ST_Point(latitude,longitude), 4326), ST_SRID(rast)))
FROM public.elevation

I'd like to be able to constrain the query so that it only looks up the value from the raster that contains the latitude / longitude but I'm not quite sure how to do that. Something like this maybe

SELECT ST_Value(rast, ST_Transform(ST_SetSRID(ST_Point(latitude,longitude), 4326), ST_SRID(rast)))
FROM public.elevation
where rid = ?

How can I figure out what rid to use?  

Thanks,
Greg

Greg Flanagan

unread,
Oct 29, 2014, 8:11:21 PM10/29/14
to postgi...@googlegroups.com
I just needed to add a where clause

WHERE ST_Intersects(rast, ST_Transform(ST_SetSRID(ST_Point(lon,lat), 4326),  ST_SRID(rast)))

although this is very slow
Reply all
Reply to author
Forward
0 new messages