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

1#!/usr/bin/env python3 

2 

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. 

14 

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 

23 

24 Returns 

25 ------- 

26 resOfEarth : float 

27 the resolution (in metres/pixel) 

28 

29 Notes 

30 ----- 

31 `OpenStreetMap have tabulated a few values <https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Resolution_and_Scale>`_ . 

32 

33 Copyright 2017 Thomas Guymer [1]_ 

34 

35 References 

36 ---------- 

37 .. [1] PyGuymer3, https://github.com/Guymer/PyGuymer3 

38 """ 

39 

40 # Import standard modules ... 

41 import math 

42 

43 # Import sub-functions ... 

44 from ..consts import CIRCUMFERENCE_OF_EARTH 

45 

46 # Create short-hands ... 

47 n = pow(2, zoom) 

48 tileSize = scale * 256 # [px] 

49 

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] 

53 

54 # Return answer ... 

55 return resOfEarth