I'm trying to shift a georeferenced raster by 0.5m N and 0.5m W in QGIS using the python console:
from osgeo import gdal
# Open in read/write mode
rast_src = gdal.Open('test_raster.tif', 1)
# Get affine transform coefficients
gt = rast_src.GetGeoTransform()
# Convert tuple to list, so we can modify it
gtl = list(gt)
gtl[0] -= 0.5 # Move west 0.5 m
gtl[3] += 0.5 # Move north 0.5 m
# Save the geotransform to the raster
rast_src.SetGeoTransform(tuple(gtl))
rast_src = None # equivalent to save/close
However line #7 (gt = rast_src.GetGeoTransform()) throws an AttributeError: 'NoneType' object has no attribute 'GetGeoTransform'. The installed GDAL version is 1.11.0. The raster seems fine. So what's wrong?
Open()
call failed (returningNone
). Can you check if it works with a full path? Probably the issue is that the directory that you think you're working in isn't the one you're actually looking in. You can check this by addingimport os
andprint os.getcwd()
before the failingOpen()
call.rast_src = gdal.Open('C:\temp\raster1.tif', 1)
. I tried another file too. Can't I pick just a loaded layer?rast_src = gdal.Open('C:\\temp\\raster1.tif', 1)
. The working directory isC:\Program Files\QGIS Chugiak\bin
. If you change your comment to an answer I can tick it :)