I have written a plugin in QGIS 3 to read the band value of a pixel or from a textbox and update the value to the selected pixels. When I'm updating a single pixel or smaller group, the script is working fine. When I'm updating for a large group of pixels, the script terminating from the half way and shows the error like ".tif file is not regonised file format..."
In the below screen, I have entered band value 5 and updated the same for small area. When I tried the same for bigger area, it applies partially and shows the error as mentioned above.
Below is the code used for read, write and close the raster (.tif) file.
def change_cell_value(self, vals, x=None, y=None): if not x: x = self.px else: pass if not y: y =self.py else: pass self.gdal_raster = gdal.Open(self.raster.source(), GA_Update) #Read for nr in range(1, min(4, self.bandCount + 1)): s = vals[nr-1] rbuf = s.tostring() self.bands[nr]['data'].WriteRaster(x, y, 1, 1, rbuf, buf_type=self.bands[nr]['qtype']) #Write self.bands[nr]['data'] = None self.bands[nr] = None self.gdal_raster = None #Close self.raster.setCacheImage(None) self.raster.triggerRepaint() self.prepare_gdal_raster(True)