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.

enter image description here

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
    if not y:
        y =self.py
    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
  • What do you mean by "update it to another pixel"? Do you mean instead value? If possible, post all your code not just opening of the raster. – 15Step Jun 22 '18 at 12:56
  • I have updated the above content with screenshot please refer. – Bhuvaneswari Jun 26 '18 at 10:32
  • What's the variable type of self.bands[1]? how did you extract individual bands to arrays? It's quite hard to debug with partial code. – 15Step Jun 27 '18 at 10:28

Your Answer

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

Browse other questions tagged or ask your own question.