2

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...

asked Dec 13, 2019 at 11:49

1 Answer 1

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

answered Dec 13, 2019 at 14:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.