Skip to content
🎉 Apache Sedona 1.8.1 is now available! Check out the new features and improvements.

RS_WorldToRasterCoord

Introduction: Returns the grid coordinate of the given world coordinates as a Point.

Format:

RS_WorldToRasterCoord(raster: Raster, point: Geometry)

RS_WorldToRasterCoord(raster: Raster, x: Double, y: Point)

Since: v1.5.0

SQL Example

SELECT RS_WorldToRasterCoord(ST_MakeEmptyRaster(1, 5, 5, -53, 51, 1, -1, 0, 0, 4326), -53, 51) from rasters;

Output:

POINT (1 1)

SQL Example

SELECT RS_WorldToRasterCoord(ST_MakeEmptyRaster(1, 5, 5, -53, 51, 1, -1, 0, 0, 4326), ST_GeomFromText('POINT (-52 51)')) from rasters;

Output:

POINT (2 1)

Note

If the given geometry point is not in the same CRS as the given raster, the given geometry will be transformed to the given raster's CRS. You can use ST_Transform to transform the geometry beforehand.