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
= fiat.io.GridSource(<some raster file>)
gs # Get the geotransform
= gs.get_geotransform()
gtf # Calculate the indices
= world2pixel(gtf, <x>, <y>) row, col