[gdal-dev] Python API ReadAsArray axis order

Javier Jimenez Shaw j1 at jimenezshaw.com
Sun Dec 4 04:02:19 PST 2022


Hi Chris

I am not an expert in python. But I had similar problems in other
environments.
At https://gdal.org/api/python/osgeo.gdal.html you can see that in many
functions the numpy array returned is always in the form "array[y][x]".
Looks like the shape in stored as "row,cols", not as "x,y".

Cheers
.___ ._ ..._ .. . ._.  .___ .. __ . _. . __..  ... .... ._ .__
Entre dos pensamientos racionales
hay infinitos pensamientos irracionales.



On Sun, 4 Dec 2022 at 09:02, Chris Crook <ccrook at linz.govt.nz> wrote:

> Hi
>
> I am using the Python GDAL API and looking at a simple TIFF image with a
> test program:
>
> from osgeo import gdal
> dataset = gdal.Open('test-gdal.tif')
> transform=dataset.GetGeoTransform()
> nx=dataset.RasterXSize
> ny=dataset.RasterYSize
> data=dataset.ReadAsArray()
> print(f"Raster xsize, ysize ({nx},{ny})")
> print(f"ReadAsArray dimensions {data.shape}")
> print(f"GeoTransform: {transform}")
>
> The output is:
>
> test_python_api.py
> Raster xsize, ysize (3,4)
> ReadAsArray dimensions (4, 3)
> GeoTransform: (22.15, 0.7, 0.0, -69.5, 0.0, 1.0)
>
>
> I am confused that the array appears transposed from the raster x,y size.
>
> Is this always the cased.  As far as I can tell the geotransform is
> assuming x,y (0-2,0-3 values) to map indices to location, which is what I
> want to do.
>
> Can I assume that the array is always transposed?  Or if not how do I
> identify when this is the case?
>
> Many thanks in advance
>
> Chris Crook
> Land Information New Zealand
>
>
>
>
>
>
> ------------------------------
>
> This message contains information, which may be in confidence and may be
> subject to legal privilege. If you are not the intended recipient, you must
> not peruse, use, disseminate, distribute or copy this message. If you have
> received this message in error, please notify us immediately (Phone 0800
> 665 463 or info at linz.govt.nz) and destroy the original message. LINZ
> accepts no responsibility for changes to this email, or for any
> attachments, after its transmission from LINZ. Thank You.
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20221204/e974be13/attachment.htm>


More information about the gdal-dev mailing list