Skip to content

Instantly share code, notes, and snippets.

@BishopGIS
Created November 9, 2020 13:37
Show Gist options
  • Save BishopGIS/b7cf7d8e86b21ab80754664e274f7e40 to your computer and use it in GitHub Desktop.
Save BishopGIS/b7cf7d8e86b21ab80754664e274f7e40 to your computer and use it in GitHub Desktop.
Test scale to zoom conversion
# -*- coding: utf-8 -*-
import math
dpi = 1000 / 39.37 / 0.28
ipm = 39.37
metersPerTile = 156543.04
def getZoomFromScale(scale):
return math.log(scale) / math.log(2)
def getResolutionForScale(scale, mpu = 1.0):
return scale / (mpu * ipm * dpi)
for scale_mult in range(6):
scale = 1000 * math.pow(10, scale_mult)
res = getResolutionForScale(scale)
zoom = getZoomFromScale(metersPerTile / res)
print('{} [{}] - {}'.format(scale, res, zoom))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment