Created
June 13, 2020 10:55
-
-
Save ThomasG77/dde20c29fd5863e4fe84d785698c4d0c to your computer and use it in GitHub Desktop.
Python functions to convert from/to zoom level to scale (assuming 96 dpi and latitude 0)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import cos, log, pi | |
def getScale(zoom_level, screen_dpi=96, latitude=0): | |
resolution = (6378137.0 * 2 * pi / 256) * cos(latitude) / (2**zoom_level) | |
return (screen_dpi * 1/0.0254 * resolution) | |
def getZoomLevel(scale, screen_dpi=96, latitude=0): | |
resolution = scale / (screen_dpi * 1/0.0254) | |
zoom_level = ((6378137.0 * 2 * pi / 256) * cos(latitude)) / resolution | |
return log(zoom_level)/log(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment