pythongdal

Pythonic way to blockshift a geotif with GDAL


I am using GDAL from osgeo to work on geotif files. I have not figured out out to use the option -a_gt to alter the geotransform and used a systen call instead.

shifted_geotransform = tuple([geoTransform[0]+shift_x, geoTransform[1],geoTransform[2],geoTransform[3]+shift_y,geoTransform[4],geoTransform[5]])

phrase = 'gdal_translate -of GTiff -a_gt '+str(shifted_geotransform[0])+\
         ' '+str(shifted_geotransform[1])+\
         ' '+str(shifted_geotransform[2])+\
         ' '+str(shifted_geotransform[3])+\
         ' '+str(shifted_geotransform[4])+\
         ' '+str(shifted_geotransform[5])+ ' '+file_in+' '+file_out

subprocess.call(phrase)

I would like to use something like

gdal.Transformer(Dataset src, Dataset dst,options)

but I have not found how to formulate the -a_gt in the options.


Solution

  • The typical way to specify the options in osgeo.gdal.Translate is by using osgeo.gdal.TranslateOptions.

    There is a parameter outputGeotransform: assigned geotransform matrix (array of 6 values) (mutually exclusive with outputBounds)

    Basic sample script:

    options = gdal.TranslateOptions(outputGeotransform=[ 0.0, 0.1, 0.0, 0.0, 0.0, 0.1 ])
    gdal.Transformer(Dataset src, Dataset dst, options)