Skip to content

Instantly share code, notes, and snippets.

@ThomasG77
Last active June 13, 2020 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasG77/d83a25504147394e352f14da510df148 to your computer and use it in GitHub Desktop.
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
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