use crate::layers::Layer;
use crate::source::input::{DataSource, InputFeature};
use crate::tile::feature::PropValue;
use super::buildings::ProcessedFeature;
pub fn process(feature: &InputFeature) -> Option<ProcessedFeature> {
match &feature.source {
DataSource::Overture { .. } => process_overture(feature),
DataSource::Osm { .. } => None,
_ => None,
}
}
fn process_overture(feature: &InputFeature) -> Option<ProcessedFeature> {
if feature.get_str("subtype") != Some("airport") || !feature.can_be_line() {
return None;
}
let (kind_detail, min_zoom) = match feature.get_str("class")? {
"runway" => ("runway", 9u8),
"taxiway" | "taxilane" => ("taxiway", 10),
_ => return None,
};
let mut properties = Vec::with_capacity(5);
properties.push(("kind".into(), PropValue::Str("aeroway".into())));
properties.push(("kind_detail".into(), PropValue::Str(kind_detail.into())));
if let Some(name) = feature.get_str("names.primary").or(feature.get_str("name")) {
properties.push(("name".into(), PropValue::Str(name.to_string())));
}
properties.push(("sort_rank".into(), PropValue::I64(400)));
properties.push(("min_zoom".into(), PropValue::I64((min_zoom + 1) as i64)));
Some(ProcessedFeature {
id: feature.id,
geometry: feature.geometry.clone(),
layer: Layer::Roads,
min_zoom,
max_zoom: 15,
sort_rank: 400,
properties,
})
}
#[cfg(test)]
mod tests {
use super::*;
use crate::source::input::DataSource;
use std::collections::HashMap;
use std::sync::Arc;
fn line() -> Arc<geo::Geometry<f64>> {
Arc::new(geo::Geometry::LineString(geo::LineString::from(vec![
(0.0, 0.0),
(1.0, 1.0),
])))
}
fn make_feature_with(
geometry: Arc<geo::Geometry<f64>>,
props: &[(&str, &str)],
) -> InputFeature {
let properties: HashMap<String, PropValue> = props
.iter()
.map(|(k, v)| (k.to_string(), PropValue::Str(v.to_string())))
.collect();
InputFeature {
id: 1,
geometry,
properties,
bbox: None,
source: DataSource::Overture {
theme: "base".into(),
otype: "infrastructure".into(),
},
}
}
fn airport(class: &str) -> InputFeature {
make_feature_with(line(), &[("subtype", "airport"), ("class", class)])
}
fn prop<'a>(result: &'a ProcessedFeature, key: &str) -> Option<&'a PropValue> {
result
.properties
.iter()
.find(|(k, _)| k == key)
.map(|(_, v)| v)
}
#[test]
fn runway_is_aeroway_runway_at_z9() {
let result = process(&airport("runway")).unwrap();
assert_eq!(result.layer, Layer::Roads);
assert_eq!(
prop(&result, "kind"),
Some(&PropValue::Str("aeroway".into()))
);
assert_eq!(
prop(&result, "kind_detail"),
Some(&PropValue::Str("runway".into()))
);
assert_eq!(result.min_zoom, 9);
}
#[test]
fn taxiway_and_taxilane_are_taxiway_at_z10() {
for class in ["taxiway", "taxilane"] {
let result = process(&airport(class)).unwrap();
assert_eq!(
prop(&result, "kind_detail"),
Some(&PropValue::Str("taxiway".into())),
"{class}"
);
assert_eq!(result.min_zoom, 10, "{class}");
}
}
#[test]
fn other_airport_classes_are_dropped() {
for class in [
"airport_gate",
"helipad",
"apron",
"airport",
"stopway",
"heliport",
] {
assert!(process(&airport(class)).is_none(), "{class}");
}
}
#[test]
fn runways_outside_airports_or_mapped_as_polygons_are_dropped() {
for subtype in ["transit", "power", "bridge", "rail", "ferry"] {
let feat = make_feature_with(line(), &[("subtype", subtype), ("class", "runway")]);
assert!(process(&feat).is_none(), "{subtype}");
}
let poly = Arc::new(geo::Geometry::Polygon(geo::Polygon::new(
geo::LineString::from(vec![(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)]),
vec![],
)));
let feat = make_feature_with(poly, &[("subtype", "airport"), ("class", "runway")]);
assert!(process(&feat).is_none());
}
#[test]
fn airport_without_class_is_dropped() {
let feat = make_feature_with(line(), &[("subtype", "airport")]);
assert!(process(&feat).is_none());
}
#[test]
fn name_extracted_from_names_primary() {
let feat = make_feature_with(
line(),
&[
("subtype", "airport"),
("class", "runway"),
("names.primary", "09L/27R"),
],
);
let result = process(&feat).unwrap();
assert_eq!(
prop(&result, "name"),
Some(&PropValue::Str("09L/27R".into()))
);
}
#[test]
fn unnamed_runway_has_no_name() {
let result = process(&airport("runway")).unwrap();
assert!(prop(&result, "name").is_none());
}
#[test]
fn min_zoom_property_is_one_above_min_zoom() {
let result = process(&airport("runway")).unwrap();
assert_eq!(prop(&result, "min_zoom"), Some(&PropValue::I64(10)));
}
#[test]
fn osm_source_returns_none() {
let mut feat = airport("runway");
feat.source = DataSource::Osm {
element_type: crate::source::input::OsmElementType::Way,
relations: vec![],
};
assert!(process(&feat).is_none());
}
#[test]
fn other_data_source_returns_none() {
let mut feat = airport("runway");
feat.source = DataSource::LandPolygons;
assert!(process(&feat).is_none());
}
}