14

I have a tiff raster in my PostGIS 2.0 database. I want to get the value of the raster at a specified lat/lon point.

I have:

  • postgresql-9.1
  • postgis-2.0-svn with raster support
  • a raster imported into PostGIS its SRID is 3035
mgri
  • 16,159
  • 6
  • 47
  • 80
avances123
  • 552
  • 7
  • 16

3 Answers3

13

You can transform the lat/lon point to raster CRS on the fly using ST_Transform(). Combined, the query looks like this:

ST_Value(your_raster, ST_Transform(ST_SetSRID(ST_MakePoint(lon,lat),4326),3035))
underdark
  • 84,148
  • 21
  • 231
  • 413
5

The function ST_value:

http://postgis.net/docs/RT_ST_Value.html

returns a raster value given a point in either x,y or lat,lon.

Paul Ramsey
  • 19,865
  • 1
  • 47
  • 57
unicoletti
  • 7,339
  • 22
  • 33
  • 1
    it works, but in this page the examples forces you to input your query in EPSG:3035, and i want to query in lat lon points.. – avances123 Sep 24 '11 at 15:49
5

While ST_Value works, you still need to spatially join to the point as well:

SELECT ST_Value(your_raster.rast, ST_Transform(ST_SetSRID(ST_MakePoint(lon,lat),4326),3035))
FROM your_raster
WHERE ST_Intersects(your_raster.rast, ST_SetSRID(ST_MakePoint(lon,lat),4326),3035))

Or with a table:

SELECT ST_Value(your_raster.rast, ST_Transform(ST_SetSRID(ST_MakePoint(your_table.lon,your_table.lat),4326),3035))
FROM your_raster
JOIN your_table ON ST_Intersects(your_raster.rast, ST_SetSRID(ST_MakePoint(your_table.lon,your_table.lat),4326),3035))
HeikkiVesanto
  • 16,433
  • 2
  • 46
  • 68