Skip to main content

geolith_tiles_builder/layers/
transit.rs

1//! Transit layer — aeroway lines emitted into the roads MVT layer.
2//!
3//! Processes features from multiple data sources:
4//! - **Overture**: `base/infrastructure` airport runways and taxiways. Rail and
5//!   ferry lines live in `transportation/segment` and are handled by the roads
6//!   layer, not here.
7//! - **OSM**: Currently no-op — Planetiler handles rail/ferry/aeroway in Roads.java
8
9use crate::layers::Layer;
10use crate::source::input::{DataSource, InputFeature};
11use crate::tile::feature::PropValue;
12
13use super::buildings::ProcessedFeature;
14
15/// Process a feature into the roads MVT layer (transit subtype).
16///
17/// Routes to the appropriate handler based on data source.
18/// Per Planetiler spec, transit features emit into the `roads` layer.
19pub fn process(feature: &InputFeature) -> Option<ProcessedFeature> {
20    match &feature.source {
21        DataSource::Overture { .. } => process_overture(feature),
22        // OSM transit is a no-op in the Java Planetiler spec
23        DataSource::Osm { .. } => None,
24        _ => None,
25    }
26}
27
28/// Process Overture `base/infrastructure` features into the roads MVT layer.
29///
30/// Mirrors protomaps `Roads.processOverture`: only `subtype = airport` lines
31/// with class `runway`, `taxiway`, or `taxilane` are kept. `kind_detail` is
32/// `runway` or `taxiway`, which is what the protomaps style filters on.
33/// Gates, helipads, aprons, and airport points are not road-layer features.
34fn process_overture(feature: &InputFeature) -> Option<ProcessedFeature> {
35    if feature.get_str("subtype") != Some("airport") || !feature.can_be_line() {
36        return None;
37    }
38
39    let (kind_detail, min_zoom) = match feature.get_str("class")? {
40        "runway" => ("runway", 9u8),
41        "taxiway" | "taxilane" => ("taxiway", 10),
42        _ => return None,
43    };
44
45    let mut properties = Vec::with_capacity(5);
46    properties.push(("kind".into(), PropValue::Str("aeroway".into())));
47    properties.push(("kind_detail".into(), PropValue::Str(kind_detail.into())));
48
49    if let Some(name) = feature.get_str("names.primary").or(feature.get_str("name")) {
50        properties.push(("name".into(), PropValue::Str(name.to_string())));
51    }
52
53    properties.push(("sort_rank".into(), PropValue::I64(400)));
54    properties.push(("min_zoom".into(), PropValue::I64((min_zoom + 1) as i64)));
55
56    Some(ProcessedFeature {
57        id: feature.id,
58        geometry: feature.geometry.clone(),
59        layer: Layer::Roads,
60        min_zoom,
61        max_zoom: 15,
62        sort_rank: 400,
63        properties,
64    })
65}
66
67#[cfg(test)]
68mod tests {
69    use super::*;
70    use crate::source::input::DataSource;
71    use std::collections::HashMap;
72    use std::sync::Arc;
73
74    fn line() -> Arc<geo::Geometry<f64>> {
75        Arc::new(geo::Geometry::LineString(geo::LineString::from(vec![
76            (0.0, 0.0),
77            (1.0, 1.0),
78        ])))
79    }
80
81    fn make_feature_with(
82        geometry: Arc<geo::Geometry<f64>>,
83        props: &[(&str, &str)],
84    ) -> InputFeature {
85        let properties: HashMap<String, PropValue> = props
86            .iter()
87            .map(|(k, v)| (k.to_string(), PropValue::Str(v.to_string())))
88            .collect();
89        InputFeature {
90            id: 1,
91            geometry,
92            properties,
93            bbox: None,
94            source: DataSource::Overture {
95                theme: "base".into(),
96                otype: "infrastructure".into(),
97            },
98        }
99    }
100
101    fn airport(class: &str) -> InputFeature {
102        make_feature_with(line(), &[("subtype", "airport"), ("class", class)])
103    }
104
105    fn prop<'a>(result: &'a ProcessedFeature, key: &str) -> Option<&'a PropValue> {
106        result
107            .properties
108            .iter()
109            .find(|(k, _)| k == key)
110            .map(|(_, v)| v)
111    }
112
113    #[test]
114    fn runway_is_aeroway_runway_at_z9() {
115        let result = process(&airport("runway")).unwrap();
116        assert_eq!(result.layer, Layer::Roads);
117        assert_eq!(
118            prop(&result, "kind"),
119            Some(&PropValue::Str("aeroway".into()))
120        );
121        assert_eq!(
122            prop(&result, "kind_detail"),
123            Some(&PropValue::Str("runway".into()))
124        );
125        assert_eq!(result.min_zoom, 9);
126    }
127
128    #[test]
129    fn taxiway_and_taxilane_are_taxiway_at_z10() {
130        for class in ["taxiway", "taxilane"] {
131            let result = process(&airport(class)).unwrap();
132            assert_eq!(
133                prop(&result, "kind_detail"),
134                Some(&PropValue::Str("taxiway".into())),
135                "{class}"
136            );
137            assert_eq!(result.min_zoom, 10, "{class}");
138        }
139    }
140
141    /// Classes seen under `subtype = airport` in the 2026-08-19.0 release
142    /// that are not road-layer lines.
143    #[test]
144    fn other_airport_classes_are_dropped() {
145        for class in [
146            "airport_gate",
147            "helipad",
148            "apron",
149            "airport",
150            "stopway",
151            "heliport",
152        ] {
153            assert!(process(&airport(class)).is_none(), "{class}");
154        }
155    }
156
157    #[test]
158    fn runways_outside_airports_or_mapped_as_polygons_are_dropped() {
159        for subtype in ["transit", "power", "bridge", "rail", "ferry"] {
160            let feat = make_feature_with(line(), &[("subtype", subtype), ("class", "runway")]);
161            assert!(process(&feat).is_none(), "{subtype}");
162        }
163        // An airport runway mapped as a polygon is dropped too.
164        let poly = Arc::new(geo::Geometry::Polygon(geo::Polygon::new(
165            geo::LineString::from(vec![(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)]),
166            vec![],
167        )));
168        let feat = make_feature_with(poly, &[("subtype", "airport"), ("class", "runway")]);
169        assert!(process(&feat).is_none());
170    }
171
172    #[test]
173    fn airport_without_class_is_dropped() {
174        let feat = make_feature_with(line(), &[("subtype", "airport")]);
175        assert!(process(&feat).is_none());
176    }
177
178    #[test]
179    fn name_extracted_from_names_primary() {
180        let feat = make_feature_with(
181            line(),
182            &[
183                ("subtype", "airport"),
184                ("class", "runway"),
185                ("names.primary", "09L/27R"),
186            ],
187        );
188        let result = process(&feat).unwrap();
189        assert_eq!(
190            prop(&result, "name"),
191            Some(&PropValue::Str("09L/27R".into()))
192        );
193    }
194
195    #[test]
196    fn unnamed_runway_has_no_name() {
197        let result = process(&airport("runway")).unwrap();
198        assert!(prop(&result, "name").is_none());
199    }
200
201    #[test]
202    fn min_zoom_property_is_one_above_min_zoom() {
203        let result = process(&airport("runway")).unwrap();
204        assert_eq!(prop(&result, "min_zoom"), Some(&PropValue::I64(10)));
205    }
206
207    #[test]
208    fn osm_source_returns_none() {
209        let mut feat = airport("runway");
210        feat.source = DataSource::Osm {
211            element_type: crate::source::input::OsmElementType::Way,
212            relations: vec![],
213        };
214        assert!(process(&feat).is_none());
215    }
216
217    #[test]
218    fn other_data_source_returns_none() {
219        let mut feat = airport("runway");
220        feat.source = DataSource::LandPolygons;
221        assert!(process(&feat).is_none());
222    }
223}