Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
translate ▾

Modern-Apps.git / scripts / maps / osm_ingest / src / testpbf_s1.rs

testpbf_s1.rs152 lines · 6.2 KiBRaw
1fn region_block() -> Vec<u8> {
2 let mut st = StringTable::new();
3 let k_amenity = st.id("amenity");
4 let v_cafe = st.id("cafe");
5 let k_name = st.id("name");
6 let v_inside = st.id("Inside Cafe");
7 let v_outside = st.id("Outside Cafe");
8 let k_place = st.id("place");
9 let v_town = st.id("town");
10 let v_testville = st.id("Testville");
11 let k_type = st.id("type");
12 let k_boundary = st.id("boundary"); // also the value of `type=*`
13 let v_admin = st.id("administrative");
14 let k_admin_level = st.id("admin_level");
15 let v_eight = st.id("8");
16 let v_green = st.id("Green Boundary");
17 let k_leisure = st.id("leisure");
18 let v_park = st.id("park");
19 let role_outer = st.id("outer");
20 let role_label = st.id("label");
21
22 let nodes: Vec<FixtureNode> = REGION_NODES
23 .iter()
24 .map(|(id, lat, lon)| {
25 let tags = match *id {
26 REGION_INSIDE_CAFE_ID => vec![(k_amenity, v_cafe), (k_name, v_inside)],
27 REGION_OUTSIDE_CAFE_ID => vec![(k_amenity, v_cafe), (k_name, v_outside)],
28 REGION_TOWN_NODE_ID => vec![(k_place, v_town), (k_name, v_testville)],
29 _ => Vec::new(),
30 };
31 (*id, *lat, *lon, tags)
32 })
33 .collect();
34 let dense = dense_group(&nodes);
35 let ways = [way(REGION_RING_WAY_ID, &[], &[11, 12, 13, 14, 11])];
36 let rels = [relation(
37 REGION_BOUNDARY_ID,
38 &[
39 (k_type, k_boundary),
40 (k_boundary, v_admin),
41 (k_admin_level, v_eight),
42 (k_name, v_green),
43 (k_leisure, v_park),
44 ],
45 // Ascending, so the delta encoding stays small.
46 &[(REGION_TOWN_NODE_ID, role_label, 0), (REGION_RING_WAY_ID, role_outer, 1)],
47 )];
48
49 let mut node_group = Vec::new();
50 bytes_field(2, &dense, &mut node_group);
51 let mut way_group = Vec::new();
52 for w in &ways {
53 bytes_field(3, w, &mut way_group);
54 }
55 let mut rel_group = Vec::new();
56 for r in &rels {
57 bytes_field(4, r, &mut rel_group);
58 }
59
60 let mut block = Vec::new();
61 bytes_field(1, &st.encode(), &mut block);
62 bytes_field(2, &node_group, &mut block);
63 bytes_field(2, &way_group, &mut block);
64 bytes_field(2, &rel_group, &mut block);
65 varint_field(17, 100, &mut block); // granularity
66 block
67}
68
69/// Write the region-link fixture to a unique temp directory.
70pub fn write_region_sample(tag: &str) -> (std::path::PathBuf, std::path::PathBuf) {
71 write_pbf(tag, &pbf_from_block(&region_block()))
72}
73
74// ---- the vector-layer fixture --------------------------------------------
75//
76// A SECOND fixture rather than more features in the one above. The road-graph and
77// POI tests assert exact counts against it (`ways.len() == 3`, `records == 3`,
78// `NODE_COUNT`), so every addition there ripples into four modules' tests and
79// makes each of them slightly less about what it is testing. The vector layers
80// need different elements anyway.
81
82/// `highway=speed_camera` with a direction.
83pub const CAMERA_NODE_ID: i64 = 1001;
84/// `man_made=surveillance` + `surveillance:type=ALPR` + a Flock operator, so it
85/// hits the ALPR branch by two independent signals.
86pub const ALPR_NODE_ID: i64 = 1003;
87pub const STOP_SIGN_NODE_ID: i64 = 1006;
88pub const SIGNALS_NODE_ID: i64 = 1007;
89/// A named cafe: tagged, but not road furniture. The negative control.
90pub const LAYERS_CAFE_NODE_ID: i64 = 1008;
91
92/// `highway=residential` + `maxspeed=25 mph`, the raw-string case.
93pub const MAXSPEED_WAY_ID: i64 = 3001;
94/// `highway=motorway` + `maxspeed=none`, which the graph's parser would collapse
95/// to 0 and this layer must keep verbatim. Also the `roads` layer's
96/// fully-attributed way: a oneway bridge with lanes, turn lanes, width and layer.
97pub const MAXSPEED_NONE_WAY_ID: i64 = 3002;
98/// `highway=service` with no speed limit at all. The negative control.
99pub const NO_MAXSPEED_WAY_ID: i64 = 3003;
100/// `railway=subway`, a transit line in its own right.
101pub const RAILWAY_WAY_ID: i64 = 5001;
102/// `railway=narrow_gauge`, which folds into `rail`.
103pub const NARROW_GAUGE_WAY_ID: i64 = 5002;
104/// `railway=platform`, which is not a line. The negative control.
105pub const PLATFORM_WAY_ID: i64 = 5003;
106/// A **closed** `railway=platform` way, carried by the route relation below as a
107/// `role=platform` member. The shape that drew a box around every station.
108pub const ROUTE_PLATFORM_WAY_ID: i64 = 5004;
109/// `type=route` + `route=subway`, with a colour and a ref, over two member ways
110/// plus a `role=platform` member that is not part of the line.
111pub const ROUTE_RELATION_ID: i64 = 9001;
112/// `type=route` + `route=bus`, which this layer drops.
113pub const BUS_RELATION_ID: i64 = 9002;
114/// `type=boundary` + `boundary=administrative` + `admin_level=8`, with an outer
115/// ring split across two ways and one inner ring (a hole).
116pub const ADMIN_CITY_RELATION_ID: i64 = 9101;
117/// The same, but `admin_level=6`: a county, which the city layer drops.
118pub const ADMIN_COUNTY_RELATION_ID: i64 = 9102;
119
120/// The corners of [`ROUTE_PLATFORM_WAY_ID`], well clear of every other fixture
121/// coordinate so its absence from the route's geometry can be asserted directly.
122const ROUTE_PLATFORM_NODES: [(i64, i32, i32); 4] = [
123 (2201, 377_950_000, -1_224_050_000),
124 (2202, 377_950_000, -1_224_040_000),
125 (2203, 377_960_000, -1_224_040_000),
126 (2204, 377_960_000, -1_224_050_000),
127];
128
129/// Way ids the admin boundary is assembled from.
130pub const ADMIN_OUTER_WAY_A: i64 = 7001;
131pub const ADMIN_OUTER_WAY_B: i64 = 7002;
132pub const ADMIN_INNER_WAY: i64 = 7003;
133
134/// Node ids the vector-layer fixture's ways are built from.
135const WAY_NODE_IDS: [i64; 6] = [2001, 2002, 2003, 2004, 2005, 2006];
136
137/// The admin boundary's outer ring corners, then its hole's corners. A 0.04-degree
138/// square near the other fixture geometry, with a 0.01-degree hole inside it.
139const ADMIN_NODES: [(i64, i32, i32); 8] = [
140 (2101, 378_000_000, -1_224_000_000),
141 (2102, 378_000_000, -1_223_600_000),
142 (2103, 378_400_000, -1_223_600_000),
143 (2104, 378_400_000, -1_224_000_000),
144 (2111, 378_100_000, -1_223_900_000),
145 (2112, 378_100_000, -1_223_800_000),
146 (2113, 378_200_000, -1_223_800_000),
147 (2114, 378_200_000, -1_223_900_000),
148];
149
150/// One node in the vector-layer fixture: `(id, lat_e7, lon_e7, tags)`.
151type FixtureNode = (i64, i32, i32, Vec<(u32, u32)>);
152