0

I have a GeoTiff file with dimensions 300 x 300 and 8760 bands (hourly for one full year). I am testing some code that opens the file, updates ONE band and exits - but I am finding that the file size almost doubles when I exit the file, despite the new band being the same data type etc. Code is as follows:

I am creating the GeoTiff file using the following creation options using many singular GeoTiff files:

gdal_merge.py -separate -co BIGTIFF=YES -co COMPRESS=DEFLATE -co PREDICTOR=1 -co TILED=YES -co BLOCKXSIZE=64 -co BLOCKYSIZE=64 -o block64.tif *.tif

The file size is 947MB.

I am then updating the file using the following code:

ds = gdal.Open("block64.tif", gdal.GA_Update) 

# Some simple operation to change band values
arr = ds.GetRasterBand(11).ReadAsArray() / 2
ds.GetRasterBand(11).WriteArray(arr)
ds.FlushCache()
ds = None

The file size is now 1.9GB.

My preliminary conclusion is that the compression/creation options are not being applied once I've updated and exited the file. Is there any way to re-compress/reapply the options once I close the file?

  • Compressed tiff is not optimal for updating but doubled size feels too much. Perhaps you could try something similar to the create vrt route in this wiki document trac.osgeo.org/gdal/wiki/UserDocs/…. If you do not get help from gis.stackexchange you should write and ask from the gdal-dev mailing list. – user30184 Mar 28 at 13:47
  • More of a workaround than a real answer, but you could read all of the bands, remove the file, and recreate it with your updates. – mikewatt Mar 28 at 23:08
  • I could... and that's the answer I've come up with so far, but I'm trying to make the process as quick as possible and rewriting large files takes time (I'm updating files server-side and need to be quick to not impact client-side I/O requests). – tda Mar 29 at 8:32

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.