0

I have geotiff file which I have read into an numpy array as described in the link below:

Working with TIFFs (import, export) in Python using numpy

The size of the Geotiff array that I have is (465,465) and I have acquired the meta data of the file using gdalinfo and it's using WGS84 as it's CRS.

What I wish to do with the file is to translate the x y lat lon co-ordinates that I see in QGIS and Gdalinfo to actual positions of points in the imported numpy array, how would I go about doing this?

Community
  • 1
  • 1
cd123
  • 511
  • 1
  • 5
  • 15

1 Answers1

0

You need to use the geotransform, from an opened GDAL dataset you can get it with:

gt = ds.GetGeoTransform()

From the GDAL documentation:

The affine transform consists of six coefficients returned by GDALDataset::GetGeoTransform() which map pixel/line coordinates into georeferenced space using the following relationship:

Xgeo = GT(0) + Xpixel*GT(1) + Yline*GT(2)
Ygeo = GT(3) + Xpixel*GT(4) + Yline*GT(5)

https://gdal.org/user/raster_data_model.html

If your raster is not rotated, its fairly simple, just subtract the origin and divide by the resolution.

There are several libraries which can perform such an affine transformation, for example the aptly named 'affine' library. A detailed explanation on its usage can be found at:

http://www.perrygeo.com/python-affine-transforms.html

user27874
  • 312
  • 3
  • 20
Rutger Kassies
  • 61,630
  • 17
  • 112
  • 97