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?
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 georef georef georef