1

I have a raster file (Geotiff) and try to write a plugin that can change the value of one cell in a raster (== array cell). I know how to get a QGIS point but how can I get the array index from on click on the canvas?

1

You have to calculate these two values.

Georeferency is a tuple with 6 numbers: X coordinate of origin (upper left corner), horizontal resolution, rotation of X axis, Y coordinate, vertical resolution, rotation of Y axis.

You can use this pattern to calculate indexes:

COL = (X - OX) / RX
ROW = (Y - OY) / RY

X, Y are coordinates of pixel OX, OY are coordinates of origin Rx, RY are resolutions

COL is X index, ROW is Y index

With GDAL you can easily get those values, just open your data source (raster) and use:

georef = dataSource.GetGeoTransform()

Than you can get your values with indexes (order like above):

georef[0]
georef[3]
georef[1]
georef[5]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.