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?

3
  • 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
    Commented Jan 20, 2020 at 18:44
  • You will have to open the raster to get that information. More details here: gis.stackexchange.com/a/243648/8104
    – Aaron
    Commented Feb 25, 2020 at 9: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 Commented Feb 25, 2020 at 12:09

0

Your Answer

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

Browse other questions tagged or ask your own question.