Calculate size of pixel on a mercator xyz tile
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
import math | |
def pixel_size(z, lat, circ=40075160): | |
""" | |
Returns the size of a pixel (units same as circumference) | |
Parameters: | |
z: zoom level | |
lat: latitude in degrees | |
circ: circumference (default = 40075160 meters) | |
Notes: | |
spheroid calculation may be off slightly from true ellipsoid | |
""" | |
return circ * math.cos(math.radians(lat)) / (2 ** (z + 8)) | |
if __name__ == "__main__": | |
assert round(pixel_size(z=5, lat=0)) == 4892 | |
assert round(pixel_size(z=5, lat=45)) == 3459 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment