I have a raster layer with a corresponding world file. An external program changes the translation parameters in the world file, so I reload the raster by calling
layer.triggerRepaint()
as described in this answer. As desired, the new parameters are loaded, and the image visibly moves to its new position.
However, the canvas clips the raster to the rectangle that it initially occupied, so, for example, if the raster has been shifted to the right by 10 units, all data within 10 units of the right edge are no longer displayed. If I remove the layer and add the raster anew, the whole image is visible in its new location, but this is tedious, and other layer settings (e.g. style, transparency) are lost. I can see in the Python console that the problem is that the layer extent does not change when triggerRepaint
is called (whereas the extent of the new layer from re-adding the raster is different from the extent of the original layer). Is there a way to use Python to reset / update the extent of the layer so that the entire raster is displayed in the new location?
I have tried
layer.dataProvider().reloadData()
layer.dataProvider().updateExtents()
to no avail.