Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
Good reply by nickves, but lat and long seem switched in 'ST_GEOMFROMTEXT()'. – Franck Theeten Jun 15 '15 at 19:42

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

     ST_Value(rast, ST_Transform(ST_GeomFromText('POINT((lon lat)',4326),mysrid)) 
     ST_Intersects(rast,ST_GeomFromText('POINT(lon lat)',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:


EDIT: Changed the order of params in function ST_POINT() since they are (lon lat) and not the other way around as Franck Theeten noticed above.

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


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.