world2pixel

gis.util.world2pixel(gtf, x, y)

Calculate the pixel location based on coordinates.

(Thanks to the ogr cookbook!)

Parameters

Name Type Description Default
gtf tuple The geotransform of a grid dataset. Can be optained via the get_geotransform method. Has the following shape: (left, xres, xrot, upper, yrot, yres). required
x float | int The x coordinates of a point required
y float | int The y coordinates of a point required

Returns

Type Description
tuple Row and column indices.

Examples

# Load a dataset
gs = fiat.io.GridSource(<some raster file>)
# Get the geotransform
gtf = gs.get_geotransform()
# Calculate the indices
row, col = world2pixel(gtf, <x>, <y>)
Back to top