Modern Apps git

← Modern-Apps.git

mamaps: bake place-label to boundary link from relation label members

Commit
95d354d99d86da41fc56ddf17521cd88cbf2b41c
Author
vayun-mathur <[email protected]>
When
2026-09-21 23:29 UTC (2 months ago)
Parents
b75ff30

Diff

library/tilecodec/src/main/rust/src/mamaps/body.rs
diff --git a/library/tilecodec/src/main/rust/src/mamaps/body.rs b/library/tilecodec/src/main/rust/src/mamaps/body.rsindex 9d2b0ce768..2649505ea5 100644--- a/library/tilecodec/src/main/rust/src/mamaps/body.rs+++ b/library/tilecodec/src/main/rust/src/mamaps/body.rs@@ -73,7 +73,7 @@ pub use model::{     BUILDING_ATTRS_LEN, Body, BuildingAttrs, Carriageway, Feature, Heightmap, ID_NONE, LANE_LEFT,     LANE_MERGE_TO_LEFT, LANE_MERGE_TO_RIGHT, LANE_NONE, LANE_REVERSE, LANE_RIGHT, LANE_SHARP_LEFT,     LANE_SHARP_RIGHT, LANE_SLIGHT_LEFT, LANE_SLIGHT_RIGHT, LANE_THROUGH, LaneTurns, Layer,-    MarkingConvention, NAME_NONE, Part, ROOF_DOME, ROOF_FLAT, ROOF_GABLED, ROOF_HIPPED,+    MarkingConvention, NAME_NONE, Part, REGION_NONE, ROOF_DOME, ROOF_FLAT, ROOF_GABLED, ROOF_HIPPED,     ROOF_ORIENT_ACROSS, ROOF_ORIENT_ALONG, ROOF_ORIENT_MAX, ROOF_PYRAMIDAL, ROOF_SHAPE_MAX,     ROOF_SKILLION, };
scripts/maps/mamaps_build/src/extract.rs
diff --git a/scripts/maps/mamaps_build/src/extract.rs b/scripts/maps/mamaps_build/src/extract.rsindex 4ec4b83ea0..2bd13d11da 100644--- a/scripts/maps/mamaps_build/src/extract.rs+++ b/scripts/maps/mamaps_build/src/extract.rs@@ -44,7 +44,7 @@ use std::collections::HashMap; use std::path::Path;  use osm_ingest::nodeloc::{resolve_nodes_with, NodeLocations};-use osm_ingest::osm::{visit_block, Element, NodeView, MEMBER_WAY};+use osm_ingest::osm::{visit_block, Element, NodeView, MEMBER_NODE, MEMBER_WAY}; use osm_ingest::pbf::{self, KIND_RELATIONS, KIND_WAYS}; use osm_ingest::proto::{err, Result}; use osm_ingest::rings::{self, MemberWay, RingStats};
scripts/maps/mamaps_build/src/extract_part1.rs
diff --git a/scripts/maps/mamaps_build/src/extract_part1.rs b/scripts/maps/mamaps_build/src/extract_part1.rsindex 1a0625c26a..f6b6f9933f 100644--- a/scripts/maps/mamaps_build/src/extract_part1.rs+++ b/scripts/maps/mamaps_build/src/extract_part1.rs@@ -15,7 +15,7 @@ pub fn extract(     graph: &Path,     spill_path: &Path,     region: Option<osm_ingest::bbox::BBox>,-) -> Result<(Store, Stats)> {+) -> Result<(Store, Stats, HashMap<u64, u64>)> {     // Stage A's boundaries are printed with their elapsed time so an external RSS sampler can say     // which of them the peak belongs to. Three candidates sit within seconds of each other -- the ref     // vector, the id index built beside it, and the node pass's per-chunk accumulators -- and@@ -126,7 +126,15 @@ pub fn extract(         spill_path,         &mark,     )?;-    Ok((store, stats))+    // The place-label -> boundary link, tagged into the id space the archive uses (a place carries+    // its node id tagged as a node; the mask keys on the boundary's relation id tagged as a+    // relation). The tiler stamps each `places` label with its linked id from this.+    let region_links: HashMap<u64, u64> = pass1+        .region_label_nodes+        .iter()+        .map(|(&node, &rel)| (tagged_id(node, ELEMENT_NODE), tagged_id(rel, ELEMENT_RELATION)))+        .collect();+    Ok((store, stats, region_links)) }  /// What pass 1 hands the later phases: relations stay resident, corridors@@ -140,6 +148,12 @@ struct Pass1Out {     way_max_ref: i64,     /// The sealed ways spill, shared by refcount with every later reader.     ways_anon: std::sync::Arc<tile_build::anon::AnonStore>,+    /// `admin_centre`/`label` node member -> its boundary relation id, both raw OSM ids, for every+    /// relation that carries a region shape. The authoritative half of the place->boundary link:+    /// OSM points a boundary relation at its own label node directly, so no geometry test is needed.+    /// `label` wins over `admin_centre` when a relation lists both, since `label` is the place node+    /// the map actually renders.+    region_label_nodes: HashMap<i64, i64>, }  /// Pass 1 (ways + relations) plus the corridor promotion. Moved whole from@@ -169,6 +183,9 @@ fn run_pass1(     // planet extract is most of the file.     let mut ways = WaySink::create_anon(&ways_path)?;     let mut relations: Vec<Relation> = Vec::new();+    // `admin_centre`/`label` node member -> boundary relation id (raw), gathered as region shapes+    // are classified below. See [`Pass1Out::region_label_nodes`].+    let mut region_label_nodes: HashMap<i64, i64> = HashMap::new();     // Road ways carrying a `ref`, for the corridor pass below. A small minority of ways,     // and the only thing pass 1 keeps in memory besides the relations.     let mut corridors: Vec<crate::corridor::Segment> = Vec::new();@@ -183,6 +200,7 @@ fn run_pass1(                 Vec::<(i64, Way)>::new(),                 Vec::<Relation>::new(),                 Vec::<crate::corridor::Segment>::new(),+                Vec::<(i64, i64)>::new(),             )         },         |state, block| {@@ -301,6 +319,20 @@ fn run_pass1(                             if let Some(shape) =                                 schema::boundaries::region_area(&relation.tags, false)                             {+                                // The boundary points at its own label/centre node directly: record+                                // that node -> this relation so the place label it becomes can carry+                                // the id. `label` overwrites `admin_centre` (the label node is the+                                // one that renders; admin_centre is the capital, a different node).+                                for m in relation.members.iter() {+                                    if m.kind == MEMBER_NODE && m.role == b"admin_centre" {+                                        state.3.push((m.id, relation.id));+                                    }+                                }+                                for m in relation.members.iter() {+                                    if m.kind == MEMBER_NODE && m.role == b"label" {+                                        state.3.push((m.id, relation.id));+                                    }+                                }                                 state.1.push(Relation {                                     class: shape,                                     members: members.clone(),@@ -328,7 +360,7 @@ fn run_pass1(             })?;             Ok(kinds)         },-        |(chunk_ways, chunk_relations, chunk_corridors)| {+        |(chunk_ways, chunk_relations, chunk_corridors, chunk_label_nodes)| {             // Chunks arrive in file order and a PBF's ways are sorted by id, so appending here             // leaves the file in ascending id order. `WaySink::push` refuses an id that does not             // advance rather than letting an unsorted file reorder the archive silently.@@ -347,6 +379,10 @@ fn run_pass1(             }             relations.extend(chunk_relations);             corridors.extend(chunk_corridors);+            // `label` was pushed after `admin_centre`, so inserting in order lets the label win.+            for (node_id, rel_id) in chunk_label_nodes {+                region_label_nodes.insert(node_id, rel_id);+            }             Ok(())         },     )?;@@ -372,5 +408,6 @@ fn run_pass1(         way_refs,         way_max_ref,         ways_anon,+        region_label_nodes,     }) }\ No newline at end of file
scripts/maps/mamaps_build/src/main_part1.rs
diff --git a/scripts/maps/mamaps_build/src/main_part1.rs b/scripts/maps/mamaps_build/src/main_part1.rsindex cba5a043b7..a0fd9ca26d 100644--- a/scripts/maps/mamaps_build/src/main_part1.rs+++ b/scripts/maps/mamaps_build/src/main_part1.rs@@ -55,7 +55,7 @@ fn run(     // an empty graph dir with no `metadata.bin`, paid for in full.     check_graph_dir(&graph_dir, run.region)?; -    let (store, stats) = extract::extract(+    let (store, stats, region_links) = extract::extract(         input,         layers,         &run.coastline,@@ -108,6 +108,9 @@ fn run(             stats.lanes_inherited,         );     }+    if !region_links.is_empty() {+        println!("  including {} place-label -> boundary link(s)", region_links.len());+    }      // The build id identifies the *data*: change the input and every reader has to drop its     // cache. Derived rather than asked for, so a forgotten input cannot silently republish@@ -133,6 +136,7 @@ fn run(         // Beside the archive, as the feature spill is. One zoom at a time, removed as each finishes.         scratch: scratch_path(out),         dem,+        region_links,     };     let (bytes, per_zoom) = tiler::build(&store, &settings).map_err(|e| e.to_string())?;     tiler::check_not_empty(&per_zoom).map_err(|e| e.to_string())?;
scripts/maps/mamaps_build/src/rings_part1.rs
diff --git a/scripts/maps/mamaps_build/src/rings_part1.rs b/scripts/maps/mamaps_build/src/rings_part1.rsindex e42fa02aa8..0bf7e5801f 100644--- a/scripts/maps/mamaps_build/src/rings_part1.rs+++ b/scripts/maps/mamaps_build/src/rings_part1.rs@@ -292,6 +292,7 @@ mod tests {             scratch: std::env::temp_dir()                 .join(format!("mamaps_rings_{}.tilechunks", std::process::id())),             dem: crate::dem::Dem::from_grids(14, 17, Vec::new()),+            region_links: std::collections::HashMap::new(),         };         let store = crate::store::Store::of(&features).expect("spill");         let (bytes, stats) = crate::tiler::build(&store, &settings).expect("build");
scripts/maps/mamaps_build/src/tiler.rs
diff --git a/scripts/maps/mamaps_build/src/tiler.rs b/scripts/maps/mamaps_build/src/tiler.rsindex 58c738bbcd..8a07ba21c8 100644--- a/scripts/maps/mamaps_build/src/tiler.rs+++ b/scripts/maps/mamaps_build/src/tiler.rs@@ -256,6 +256,11 @@ pub struct Settings {     /// See [`crate::dem::Dem`]. A tile with no DEM under it carries no heightmap     /// section (stays 16-byte).     pub dem: crate::dem::Dem,+    /// Place-label id (tagged node) -> the tagged relation id of the admin boundary it names, from+    /// stage A. The tiler stamps each `places` label whose id is a key here with the linked id in+    /// the body's region-link table, so a tap on the label outlines that exact region. Empty when no+    /// links were found (the section is then omitted from every tile).+    pub region_links: std::collections::HashMap<u64, u64>, }  /// One chunk's share of a zoom, keyed on `(tile id, layer id)`.
scripts/maps/mamaps_build/src/tiler_part1.rs
diff --git a/scripts/maps/mamaps_build/src/tiler_part1.rs b/scripts/maps/mamaps_build/src/tiler_part1.rsindex 8a3e68fb7b..e246150244 100644--- a/scripts/maps/mamaps_build/src/tiler_part1.rs+++ b/scripts/maps/mamaps_build/src/tiler_part1.rs@@ -82,7 +82,7 @@ pub fn build(store: &Store, settings: &Settings) -> Result<(Vec<u8>, Vec<ZoomSta                 let _ = std::io::Write::flush(&mut std::io::stderr());             }             let encoding = std::time::Instant::now();-            let done = encode_batch(batch, &settings.dem, store.conventions())?;+            let done = encode_batch(batch, &settings.dem, store.conventions(), &settings.region_links)?;             stats.encode_ms += encoding.elapsed().as_millis() as u64;             let appending = std::time::Instant::now();             for (id, encoded, rings, lines) in done {
scripts/maps/mamaps_build/src/tiler_part5.rs
diff --git a/scripts/maps/mamaps_build/src/tiler_part5.rs b/scripts/maps/mamaps_build/src/tiler_part5.rsindex 1f6d32bf1b..2842afd11a 100644--- a/scripts/maps/mamaps_build/src/tiler_part5.rs+++ b/scripts/maps/mamaps_build/src/tiler_part5.rs@@ -2,6 +2,7 @@ fn encode_batch(     batch: Vec<(u64, Vec<ChunkEntry>)>,     dem: &crate::dem::Dem,     conventions: &crate::schema::boundaries::Conventions,+    region_links: &std::collections::HashMap<u64, u64>, ) -> Result<Vec<Encoded>> {     let on = timing();     // Split the batch into tasks by cumulative geometry cost rather than by tile count. A dense@@ -29,7 +30,7 @@ fn encode_batch(                     group                         .into_iter()                         .map(|(id, layers)| {-                            encode_tile(id, layers, dem, conventions, deflate, scratch, on)+                            encode_tile(id, layers, dem, conventions, region_links, deflate, scratch, on)                         })                         .collect::<Result<Vec<Encoded>>>()                 },@@ -52,6 +53,7 @@ fn encode_tile(     mut layers: Vec<ChunkEntry>,     dem: &crate::dem::Dem,     conventions: &crate::schema::boundaries::Conventions,+    region_links: &std::collections::HashMap<u64, u64>,     deflate: &mut tilecodec::gz::Compressor,     scratch: &mut tilecodec::mamaps::body::Scratch,     on: bool,@@ -161,6 +163,32 @@ fn encode_tile(         }         ids.push((entry.layer.layer_id, std::mem::take(&mut entry.ids)));     }+    // The region-link table: for each `places` label, the tagged relation id of the boundary it+    // names, looked up from stage A's link map by the label's own (tagged node) id — which is+    // exactly what the id table above holds. Dense-parallel to the layer's features like the id+    // table, with REGION_NONE where a label links to no region. Emitted only when at least one+    // label in the tile links somewhere, so a tile of unlinked labels (or no places at all) carries+    // no table.+    let mut region_links_table: Vec<(u8, Vec<u64>)> = Vec::new();+    if !region_links.is_empty() {+        for (layer_id, node_ids) in &ids {+            if *layer_id != tilecodec::mamaps::dict::LAYER_PLACES {+                continue;+            }+            let links: Vec<u64> = node_ids+                .iter()+                .map(|id| {+                    region_links+                        .get(id)+                        .copied()+                        .unwrap_or(tilecodec::mamaps::body::REGION_NONE)+                })+                .collect();+            if links.iter().any(|&l| l != tilecodec::mamaps::body::REGION_NONE) {+                region_links_table.push((*layer_id, links));+            }+        }+    }     // The turn-lane table, built the same way as the id table and checked against the feature count     // for the same reason: coalesce and stage C rebuild a layer's features and rewrite this     // alongside, and a drift would misattribute every lane after the first. Only emitted when some@@ -255,8 +283,7 @@ fn encode_tile(         heightmap: dem.heightmap_for(z, x, y),         carriageways,         convention,-        // Populated in the region-link phase; empty here keeps the section absent.-        region_links: Vec::new(),+        region_links: region_links_table,     };     let encoded_body = timed(on, &SERIALIZE_NANOS, || {         tilecodec::mamaps::body::serialize_into(&body, scratch)
scripts/maps/mamaps_build/src/tiler_part7.rs
diff --git a/scripts/maps/mamaps_build/src/tiler_part7.rs b/scripts/maps/mamaps_build/src/tiler_part7.rsindex 67d84c1a97..ced385cb0a 100644--- a/scripts/maps/mamaps_build/src/tiler_part7.rs+++ b/scripts/maps/mamaps_build/src/tiler_part7.rs@@ -71,6 +71,7 @@ mod tests {             build_id: 7,             scratch: scratch(),             dem: crate::dem::Dem::from_grids(14, 17, Vec::new()),+            region_links: std::collections::HashMap::new(),         }     }