mapbox / mapnik-omnivore

Node module that returns metadata about spatial files.
45 stars 19 forks source link

Raster tiling resolution breaks #133

Closed dnomadb closed 8 years ago

dnomadb commented 8 years ago

Currently mapnik-omnivore decides on a raster's maxzoom with breaks at tile resolutions. If the raster resolution is at all above this break, it "tiles up" to a higher maxzoom, effectively resulting in upsampled imagery at the maxzoom. This is problematic for raster datasets that are "snapped" to mercator tile resolutions, as rounding errors in pixel size can result in effectively a 1 zoom jump.

Here's how it works now (just higher zooms):

             ___________________________________________________
             |         |         |         |         |         |
maxzoom     z14       z15       z16       z17       z18       z19
             |_________|_________|_________|_________|_________|
             |= = = = >|= = = = >|= = = = >|= = = = >|= = = = >|
threshhold  9.55      4.78      2.39      1.19      0.6       0.3
             :         :         :         :         :         :
tiled res   9.55      4.78      2.39      1.19      0.6       0.3

Proposal

Instead of always rounding to the next higher zoom, set breaks in-between mercator tile resolution and round to the closest zoom:

             ___________________________________________________
             |         |         |         |         |         |
maxzoom     z14       z15       z16       z17       z18       z19
             |_________|_________|_________|_________|_________|
             :<= =|= =>:<= =|= =>:<= =|= =>:<= =|= =>:<= =|= =>:
threshhold   :   7.17  :   3.58  :   1.79  :   0.9   :   0.45  :
             :         :         :         :         :         :
tiled res   9.55      4.78      2.39      1.19      0.6       0.3

This would remove these rounding errors, and limit resampling to at most half the difference between mercator zooms.

Integrating this as weighted snapping (as I've been working on in colonel-mercator) would allow for flexibility in maxzoom selection. This is where any number between 0 (snap up) and 1 (snap down) is used to express where the threshold should be (here is 0.333):

             ___________________________________________________
             |         |         |         |         |         |
maxzoom     z14       z15       z16       z17       z18       z19
             |_________|_________|_________|_________|_________|
             :<= | = =>:<= | = =>:<= | = =>:<= | = =>:<= | = =>:
threshhold   :  7.37   :  3.18   :  1.59   :  0.8    :  0.4    :
             :         :         :         :         :         :
tiled res   9.55      4.78      2.39      1.19      0.6       0.3

@GretaCB @yhahn @perrygeo

springmeyer commented 8 years ago

@dnomadb - curious where this effort stands?

dnomadb commented 8 years ago

Closed via https://github.com/mapbox/mapnik-omnivore/pull/134 @springmeyer - thx for bump!