forked from enzet/map-machine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_ways.py
82 lines (63 loc) · 2.48 KB
/
test_ways.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""
Test map generation for ways.
Tests check that for the given ways described by tags, Map Machine generates
expected figures in the expected order.
"""
import numpy as np
from map_machine.constructor import Constructor
from map_machine.figure import Figure
from map_machine.geometry.boundary_box import BoundaryBox
from map_machine.geometry.flinger import MercatorFlinger
from map_machine.map_configuration import MapConfiguration
from map_machine.osm.osm_reader import OSMData, OSMWay, OSMNode, Tags
from tests import SCHEME, SHAPE_EXTRACTOR
CONFIGURATION: MapConfiguration = MapConfiguration(SCHEME)
def get_constructor(osm_data: OSMData) -> Constructor:
"""
Get custom constructor for bounds (-0.01, -0.01, 0.01, 0.01) and zoom level
18.
"""
flinger: MercatorFlinger = MercatorFlinger(
BoundaryBox(-0.01, -0.01, 0.01, 0.01), 18, osm_data.equator_length
)
constructor: Constructor = Constructor(
osm_data, flinger, SHAPE_EXTRACTOR, CONFIGURATION
)
constructor.construct_ways()
return constructor
def create_way(osm_data: OSMData, tags: Tags, index: int) -> None:
"""Create simple OSM way with two arbitrary nodes."""
nodes: list[OSMNode] = [
OSMNode({}, 1, np.array((-0.01, -0.01))),
OSMNode({}, 2, np.array((0.01, 0.01))),
]
for node in nodes:
osm_data.add_node(node)
osm_data.add_way(OSMWay(tags, index, nodes))
def test_river_and_wood() -> None:
"""
Check that river is above the wood.
See https://github.com/enzet/map-machine/issues/126
"""
osm_data: OSMData = OSMData()
create_way(osm_data, {"natural": "wood"}, 1)
create_way(osm_data, {"waterway": "river"}, 2)
figures: list[Figure] = get_constructor(osm_data).get_sorted_figures()
assert len(figures) == 2
assert figures[0].tags["natural"] == "wood"
assert figures[1].tags["waterway"] == "river"
def test_placement_and_lanes() -> None:
"""
Check that `placement` tag is processed correctly when `lanes` tag is not
specified.
See https://github.com/enzet/map-machine/issues/128
"""
osm_data: OSMData = OSMData()
create_way(osm_data, {"highway": "motorway", "placement": "right_of:2"}, 1)
get_constructor(osm_data)
def test_empty_ways() -> None:
"""Ways without nodes."""
osm_data: OSMData = OSMData()
osm_data.add_way(OSMWay({"natural": "wood"}, 1))
osm_data.add_way(OSMWay({"waterway": "river"}, 2))
assert not get_constructor(osm_data).get_sorted_figures()