[postgis-users] How to handle tiled rasters (ST_Value, grid_pt=>coord, coord=>grid_pt etc)?

Paragon Corporation lr at pcorp.us
Sat Dec 11 08:51:19 PST 2010


Stefan,

Slight addition to what I said in response to this question


> Query 4: Given one real projected coordinate (e.g. 489500/102500) return
the corresponding ("closest") grid point and its value.
> => ?  

What do you mean by grid point ? Again no concept when you are talking about
a tiled raster at least in PostGIS Raster unles you multiply by the number
of rows in the table etc.



The value would be

SELECT rid,  ST_Value(rast, 1, g.pt) As pixvalband1,
ST_World2RasterX(rast,pt) As x, ST_World2RasterY(rast,pt) As y
FROM  ch1000_tif_tiles INNER JOIN 
	(SELECT ST_GeomFromText('POINT(489500 102500)', 21781)  As pt) As g 
   ON ST_Intersects(rast,  g.pt );

Note the x and y are for that given tile.  If you want the position across
the whole grid and you have regular gridding and you imported using
raster2pgsql, then you would use something like

(rid - 1)*ST_Width(rast) + ST_World2RasterX(rast,pt) As x,  (rid -
1)*ST_Height(rast) + ST_World2RasterY(rast,pt) As y

Relevant links here
http://www.postgis.org/documentation/manual-svn/RT_ST_World2RasterCoordX.htm
l
http://www.postgis.org/documentation/manual-svn/RT_ST_World2RasterCoordY.htm
l
http://www.postgis.org/documentation/manual-svn/RT_ST_Width.html
http://www.postgis.org/documentation/manual-svn/RT_ST_Height.html

I'm curious though -- which use cases do you have where you need the grid x,
y from the original raster?


Hope that  helps,
Regina
http://www.postgis.us



_______________________________________________
postgis-users mailing list
postgis-users at postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users





More information about the postgis-users mailing list