ecometrica / gdal2mbtiles

Converts a GDAL-readable dataset into an MBTiles file. This is used to generate web maps.
Apache License 2.0
165 stars 27 forks source link

Fix "upsample_after_warp" #8

Closed mghughes closed 7 years ago

mghughes commented 7 years ago

Fixes #6

Allow for either upsampling or downsampling for the initial resampling.

To decide the native resolution, gdal.Dataset.GetNativeResolution iterates upwards through integer resolutions - defining the "native resolution" as the first where the resolution's pixel size is smaller than the original pixel size. So theoretically, this should always lead to upsampling to the next highest resolution.

But, there is an allowance for floating point error, which is based on the size of the major circumference at the given resolution. So when the resolution's pixel size is actually slightly bigger than the original pixel size, but within the error tolerance, that will be chosen as the native resolution. This in turn was leading to scaling ratios of > 1.0, which caused VImage.stretch to raise a ValueError when upsampling the image to the chosen native resolution.

This now looks at the scaling ratios and calls either stretch or shrink based on the values. I've also renamed "upsample" to "resample" in the relevent places.

mghughes commented 7 years ago

Also, there are failing tests, but that's also true of "master". I'm working on a separate PR to fix the tests.

joharohl commented 7 years ago

I think this looks good.

Possibly update gdal.Dataset.GetNativeResolution docstring to indicate that it can yield resolutions that indicate downsampling in rare cases?

mghughes commented 7 years ago

Thanks @joharohl - I'll add a bit of explanation to the docstring before merging.