Coverage for pyguymer3/openstreetmap/res.py: 12%
8 statements
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-08 18:47 +0000
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-08 18:47 +0000
1#!/usr/bin/env python3
3# Define function ...
4def res(
5 lat_deg,
6 zoom,
7 /,
8 *,
9 scale = 1,
10):
11 """
12 Calculate the resolution in the centre of a tile at a given latitude and for
13 a given zoom.
15 Parameters
16 ----------
17 lat_deg : float
18 the latitude (in degrees)
19 zoom : int
20 the zoom
21 scale : int, optional
22 the scale of the tile
24 Returns
25 -------
26 resOfEarth : float
27 the resolution (in metres/pixel)
29 Notes
30 -----
31 `OpenStreetMap have tabulated a few values <https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Resolution_and_Scale>`_ .
33 Copyright 2017 Thomas Guymer [1]_
35 References
36 ----------
37 .. [1] PyGuymer3, https://github.com/Guymer/PyGuymer3
38 """
40 # Import standard modules ...
41 import math
43 # Import sub-functions ...
44 from ..consts import CIRCUMFERENCE_OF_EARTH
46 # Create short-hands ...
47 n = pow(2, zoom)
48 tileSize = scale * 256 # [px]
50 # Calculate resolution ...
51 lat_rad = math.radians(lat_deg) # [rad]
52 resOfEarth = CIRCUMFERENCE_OF_EARTH * math.cos(lat_rad) / (float(tileSize) * n) # [m/px]
54 # Return answer ...
55 return resOfEarth