I used the gdal
module in Python to read a DEM raster. When under gdal
the DEM x and y sizes are correct (42689, 35622). As I used the ReadAsArray function, the shape of the DEM is rotated to be (35622, 42689). Is there a way to fix this or at least identify how the DEM has been rotated?
In [54]: t1.RasterYSize
Out[54]: 35622
In [55]: t1.RasterXSize
Out[55]: 42689
ta = t1.ReadAsArray
In [64]: ta.shape
Out[64]: (35622L, 42689L)
Numpy has the "y" axis as axis 0 (the first axis), and the "x" axis as axis "1" (the second axis), with a 0-based index. When you ask for ta[3,1]
, you get coordinate x=1, y=3 from an origin (0,0) at the upper left. There has been no rotation, it's just a matter of convention.
You can plot the DEM using matplotlib
or save it as new raster using gdal
and you will see that it retained the original orientation.