Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a large raster map which I loaded into postgis with 1000x1000 meter tiles... the corresponding table has about 200 rows, each row representing a tile. I want to get the raster value for a specific coordinate, but I don't know how to do that most efficiently. I did something like

select ST_Value(rast, ST_Transform(ST_GeomFromText('POINT(lat lon)',4326),mysrid)) from rasterdata;

but it gives me a lot of

Attempting to get pixel value with out of range raster coordinates:...

messages because finally only one tile contains the coordinate that I'm searching for...

Any help is highly appreciated...

share|improve this question

1 Answer 1

Add a where constrain. that way you will make use of postgis powerful gist indexes.

select 
     ST_Value(rast, ST_Transform(ST_GeomFromText('POINT(lat lon)',4326),mysrid)) 
from 
     rasterdata 
where
     ST_Intersects(rast,ST_GeomFromText('POINT(lat lon)',4326),mysrid))
 ;

Also if you haven't build the index table yet you can do this way:

CREATE INDEX [indexname] ON [tablename] USING GIST ( [geometrycolumn] );

then run VACUUM ANALYSE to populate the index:

VACUUM ANALYSE rasterdata

share|improve this answer
    
thanks a lot - works like a charm –  user16794 Apr 4 '13 at 7:32
    
user16794: Can you please mark this answer up, and mark it as "answered"? Thanks. –  BradHards Apr 4 '13 at 9:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.