QGIS PYTHON CONSOLE - TIF TRANSLATION

from osgeo import gdal\

in_path = r"C:/Users/bayan/Documents/L+U/EVLU 3004 - Ecology and Design 2/ReadingLandscapesInTime/GIS/10.1.25_MASK.tif"

dx = 10.0 # shift 10 m east (positive = right)

dy = -5.0 # shift 5 m south (negative = down)

ds = gdal.Open(in_path, gdal.GA_Update)

if ds is None:

    raise RuntimeError("Could not open raster. Check path/permissions.")

gt = ds.GetGeoTransform() # (originX, pixelW, rotX, originY, rotY, pixelH)

new_gt = (gt[0] + dx, gt[1], gt[2], gt[3] + dy, gt[4], gt[5])

ds.SetGeoTransform(new_gt)

ds = None

print(f"Raster shifted by {dx} m (east) and {dy} m (north).")