1

My raster is upside down, but it is too large to open as an array and rewrite it with a different geotransformation. Do you know a way to change the geotransformation without opening the raster as a numpy array?

my normal approach

import gdal
import numpy
r = gdal.Open(fileLocation)
band = r.GetRasterBand(1)  # bands start at one
b = band.ReadAsArray().astype(np.float16)
dst_ds = driver.Create(output_file, band.XSize, band.YSize, 1, gdal.GDT_Int16)
dst_ds.SetGeoTransform(geotransform)
dst_ds.GetRasterBand(1).WriteArray(a)
1
  • 1
    As far as I know, you shouldn't have to re-write the array to modify the geotransform. Have you tried omitting the last line and just modifying the geotransform that you're setting in the 2nd to last?
    – mikewatt
    Jun 8 at 17:29
1

This should be enough for changing the geotransformation (captured from GDAL autotests https://github.com/OSGeo/gdal/blob/master/autotest/gcore/tiff_write.py):

ds = gdal.Open('tmp/tiff57.tif', gdal.GA_Update)
ds.SetGeoTransform([100, 1, 3, 200, 3, 1])
ds = None

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.