I'm trying to update a python script using gdal, moving from a subprocess to the actual python bindings but finding the documentation a bit lacking.
My original sub process -
cmd = f"RASTER_PROJ=$(gdalsrsinfo -o wkt_esri --single-line {source_raster}) &&" \
f"gdal_translate -of {gdal_output} -co COMPRESS=LERC -co QUALITY=75 -co BLOCKSIZE=512 -a_srs \"$RASTER_PROJ\" {source_raster} {destination_raster} && " \
f"gdaladdo -r average --config COMPRESS_OVERVIEW LERC {destination_raster} 2"
subprocess.call(cmd, shell=True)
My python excerpt -
#translate
translate_options = gdal.TranslateOptions(gdal.ParseCommandLine(f"-of {gdal_output} -co COMPRESS={compression} -co QUALITY=75 -co BLOCKSIZE=512"))
gdal.Translate(destination_raster, source_raster, options=translate_options)
#addo
image = gdal.Open(destination_raster, 1)
gdal.SetConfigOption('COMPRESS_OVERVIEW LERC', 'DEFLATE')
image.BuildOverviews('AVERAGE', [2], gdal.TermProgress_nocb)
del image
This works but ideally I would be creating the overviews the same way as the translate
or alternatively setting the image variable first and inputting into the translate
function, however I haven't been able to do either without errors.
I've found no documentation on the bindings for BuildOverviews
or Addo
so am just cobbling things together from SE currently. Is there a better way?