This function calculates the pixel coordinates of a cell by using an inverse affine transformation formula based on the world coordinates and pyramid level of the cell.


point ST_World2RastCoord(raster raster_obj, integer pyramidLevel, point coord);
geometry ST_World2RastCoord(raster raster_obj, integer pyramidLevel, geometry geom);


Parameter Description
raster_obj The raster object.
pyramidLevel The pyramid level.
coord The world coordinates of the cell.
geom The geometry to be converted.


The raster object must have a valid spatial reference system identifier (SRID).

A geometry will be returned. The x coordinate is the column number in raster and the y coordinate is the row number.


select st_world2rastcoord(rast, 0, '(117.3378,26.9020)'::point) from tb_dem where id = 2;

SELECT ST_AsText(ST_world2RastCoord(rast, 0, ST_Rast2WorldCoord(rast, 0, 'POINT(511 0)'::geometry))) 
FROM tb_world2rast;
 POINT(511 0)