Skip to content

Instantly share code, notes, and snippets.

@plant99
Last active December 14, 2022 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plant99/126f0ffd28d2cda3c810804369886abe to your computer and use it in GitHub Desktop.
Save plant99/126f0ffd28d2cda3c810804369886abe to your computer and use it in GitHub Desktop.

Thanks for looking into this

Copy pasting from the original gdal2tiles.py script:

https://github.com/OSGeo/gdal/blob/84e622a2def7d0e7d37f349c95adcf1339e9a3ab/swig/python/gdal-utils/osgeo_utils/gdal2tiles.py#L2837-L2840

rx = int((ulx - geotran[0]) / geotran[1] + 0.001)
ry = int((uly - geotran[3]) / geotran[5] + 0.001)
rxsize = max(1, int((lrx - ulx) / geotran[1] + 0.5))
rysize = max(1, int((lry - uly) / geotran[5] + 0.5))

I think this calculates offsets to read from, and the length in x,y to read.

  • My doubt is why is 0.001 and 0.5 added to resolution.
  • Shouldn't they calculate incorrect offsets and sizes for low pixel resolution images, and especially in geodetic coordinates.

Further edits:

  1. I think I misunderstood basic BODMAS rules, this is a stupid question, and they don't bring significant changes to the calculated values.
  2. Still, I'd love to know some edge cases for which they're there.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment