I have two rasters of the same dimensions. Opened in QGIS, they align perfectly. However when I open them via GDAL as a numpy array, one of them is flipped and I have to flip it back to make calculations on it. See my code:
ds = gdal.Open('{}/data/tmp/one25832.tif'.format(ortascii))
band = ds.GetRasterBand(1)
arrA = band.ReadAsArray()
arrA=np.flipud(arrA)
file1 = '{}/data/tmp/two25832.tif'.format(ortascii)
ds1 = gdal.Open(file1)
band1 = ds1.GetRasterBand(1)
arrB = band1.ReadAsArray()
arrB = np.where((arrA ==999999), arrB, arrA)
Any insights on how this can happen? They have the same CRS...
1 Answer 1
Did you check the geotransform of the files?
import gdal
ds = gdal.Open(fn)
gt = ds.GetGeoTransform()
if gt[2] != 0.0 or gt[4] != 0.0:
print ('file is not stored with north up')
See the gdal documentation for more details
Explore related questions
See similar questions with these tags.