Closed mghughes closed 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.
I think this looks good.
Possibly update gdal.Dataset.GetNativeResolution
docstring to indicate that it can yield resolutions that indicate downsampling in rare cases?
Thanks @joharohl - I'll add a bit of explanation to the docstring before merging.
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
orshrink
based on the values. I've also renamed "upsample" to "resample" in the relevent places.