[GIS] GDAL raster shifting with python error: ‘NoneType’ object has no attribute ‘GetGeoTransform’

coordinate systemgdalraster

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?

Best Answer

This same issue happened to me and had nothing to do with the path name. I am able to open the raster OK, but then I find out that the methods that were previously available to me are no longer there . . . enter image description here