3

I want to get the pixel size (resolution) of a raster without opening up the raster in gdal. I currently have my script opening the raster in GDAL using gdal.Open() and getting the resolution that way. However this process is slow especially when my TIFFs are large and I have many of them.

from osgeo import gdal
data_path = "some/path/to/raster.tif"
ds = gdal.Open(data_path)
# md = ds.GetMetadata() # read metadata
gt = raster.GetGeoTransform()

pixelSizeX = gt[1]
pixelSizeY =-gt[5]

Is there a way to grab this info from the metadata or something without opening the file?

Heather
  • 39
  • 2
  • 7
    Post up an example of the code you're using. Just calling gdal.Open() shouldn't be too expensive without actually reading any data – mikewatt Jan 20 '20 at 18:44
  • You will have to open the raster to get that information. More details here: https://gis.stackexchange.com/a/243648/8104 – Aaron Feb 25 '20 at 09:45
  • Aaron is right, unless you have world files, in which case you ould just read the world file which would be a smaller memeory footprint (a few lines of text) compared to the whole image – MappaGnosis Feb 25 '20 at 12:09

0 Answers0