Skip to content

Commit 76ac282

Browse files
committed
Merge branch 'master' into v5.0-dev
2 parents 2e56986 + 624cf44 commit 76ac282

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

openmaptiles/performance.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,39 @@
4545
'null',
4646
'Empty set, useful for query validation.',
4747
(0, 0), (0, 0)), # DO NOT CHANGE THESE COORDINATES
48+
49+
# Smallest Geofabrik areas, smallest to largest (in PBF MBs)
50+
TestCase('monaco', 'Monaco (Europe)',
51+
bbox='7.4016843,43.5165358,7.5002447,43.7543525'),
52+
# saint-helena-ascension-and-tristan-da-cunha has 2,519,538 tiles, skipping
53+
TestCase('sao-tome-and-principe', 'Sao Tome and Principe (Africa)',
54+
bbox='6.2606420,-0.2135137,7.6704783,1.9257601'),
55+
TestCase('rutland', 'Rutland (Europe/England)',
56+
bbox='-0.8754549,52.2185243,-0.2619499,53.2289705'),
57+
TestCase('andorra', 'Andorra (Europe)',
58+
bbox='0.9755770,42.3242153,1.8246545,42.7883379'),
59+
TestCase('equatorial-guinea', 'Equatorial Guinea (Africa)',
60+
bbox='5.4172943,-1.6732196,12.3733400,4.3475256'),
61+
TestCase('liechtenstein', 'Liechtenstein (Europe)',
62+
bbox='9.0900979,46.9688169,9.6717077,47.5258072'),
63+
TestCase('isle-of-man', 'Isle of Man (Europe)',
64+
bbox='-20.0516670,52.0363391,-2.9134845,55.7175267'),
65+
TestCase('seychelles', 'Seychelles (Africa)',
66+
bbox='44.7888890,-12.8022220,56.4979396,-3.5120000'),
67+
TestCase('enfield', 'Enfield (Europe, England, London)',
68+
bbox='-0.3411928,51.5711773,0.0420140,51.7314462'),
69+
TestCase('comores', 'Comores (Africa)',
70+
bbox='43.0253050,-12.7197220,45.7675000,-10.9803547'),
71+
TestCase('maldives', 'Maldives (Asia)',
72+
bbox='51.0378745,-0.9074935,80.5838734,25.6240842'),
73+
TestCase('faroe-islands', 'Faroe Islands (Europe)',
74+
bbox='-14.0036840,57.5958843,9.9757588,65.3045646'),
75+
TestCase('mayotte', 'Mayotte (Europe, France)',
76+
bbox='44.7436676,-13.2732554,45.5070347,-12.3485200'),
77+
TestCase('malta', 'Malta (Europe)',
78+
bbox='5.3397500,31.2100000,29.9100000,42.9466000'),
79+
TestCase('hungary', 'Hungary (Europe)',
80+
bbox='15.8690057,43.7898070,24.7137719,49.3859161'),
4881
]}
4982

5083

openmaptiles/perfutils.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
# noinspection PyUnresolvedReferences
1111
from dataclasses_json import dataclass_json, config
1212

13-
from openmaptiles.utils import round_td
13+
from openmaptiles.utils import round_td, Bbox, deg2num
14+
15+
# If the terminal is not present, use this width
16+
# In github, comments inside the ``` block are about 88 characters
17+
DEFAULT_TERMINAL_WIDTH = 86
1418

1519

1620
class Colors:
@@ -167,9 +171,16 @@ class TestCase:
167171
query: str = None
168172
old_result: PerfTestSummary = None
169173
result: PerfTestSummary = None
174+
bbox: str = None
170175

171176
def __post_init__(self):
172177
assert self.id and self.desc
178+
if self.start is None and self.before is None and self.bbox is not None:
179+
bbox = Bbox(self.bbox)
180+
self.start = deg2num(bbox.max_lat, bbox.min_lon, self.zoom)
181+
self.before = deg2num(bbox.min_lat, bbox.max_lon, self.zoom)
182+
self.before = (self.before[0] + 1, self.before[1] + 1)
183+
173184
assert isinstance(self.start, tuple) and isinstance(self.before, tuple)
174185
assert len(self.start) == 2 and len(self.before) == 2
175186
assert self.start[0] <= self.before[0] and self.start[1] <= self.before[1]
@@ -202,7 +213,7 @@ def fmt_table(self) -> str:
202213
if self.size() > 0:
203214
pos = f" [{self.start[0]}/{self.start[1]}]" \
204215
f"x[{self.before[0] - 1}/{self.before[1] - 1}]"
205-
return f"* {self.id:10} {self.desc} ({self.size():,} " \
216+
return f"* {self.id:30} {self.desc} ({self.size():,} " \
206217
f"tiles at z{self.zoom}{pos})"
207218

208219
def format(self) -> str:
@@ -225,7 +236,7 @@ def print_graph(header, data, is_bytes=False):
225236
float_format='{:,.1f}',
226237
min_graph_length=20,
227238
separator_length=1,
228-
line_length=shutil.get_terminal_size((100, 20)).columns,
239+
line_length=shutil.get_terminal_size((DEFAULT_TERMINAL_WIDTH, 20)).columns,
229240
human_readable='cs' if is_bytes else None)
230241
for line in graph.graph(header, data):
231242
print(line)

openmaptiles/utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import math
2+
13
import asyncio
24
import re
35
import sys
@@ -19,6 +21,15 @@ def coalesce(*args):
1921
return None
2022

2123

24+
# From https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Lon..2Flat._to_tile_numbers_2
25+
def deg2num(lat_deg, lon_deg, zoom):
26+
lat_rad = math.radians(lat_deg)
27+
n = 2.0 ** zoom
28+
tile_x = int((lon_deg + 180.0) / 360.0 * n)
29+
tile_y = int((1.0 - math.asinh(math.tan(lat_rad)) / math.pi) / 2.0 * n)
30+
return tile_x, tile_y
31+
32+
2233
class Bbox:
2334
def __init__(self, bbox=None,
2435
left=BBOX_LEFT, bottom=BBOX_BOTTOM, right=BBOX_RIGHT, top=BBOX_TOP,

0 commit comments

Comments
 (0)