Last active
June 13, 2020 10:56
-
-
Save ThomasG77/d83a25504147394e352f14da510df148 to your computer and use it in GitHub Desktop.
Set scale from zoom level value for EPSG 3857. See if you want to do the opposite https://gist.github.com/ThomasG77/7c2ecd106091a335a2138dcd82565db8#file-pyqgis-add-zoom-levels-3857-py-L5
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) | |
iface.mapCanvas().zoomScale(getScale(6.7)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment