use geolith::names::push_names;
use crate::layers::Layer;
use crate::source::input::{DataSource, InputFeature};
use crate::tile::feature::PropValue;
use super::buildings::ProcessedFeature;
const MIN_CONFIDENCE: f64 = 0.65;
fn category_to_kind(category: &str) -> Option<(&'static str, u8)> {
match category {
"airport" => Some(("aerodrome", 10)),
"train_station" => Some(("station", 12)),
"bus_station" => Some(("bus_stop", 14)),
"ferry_terminal" => Some(("ferry_terminal", 12)),
"school" | "kindergarten" => Some(("school", 13)),
"university" | "college" => Some(("university", 13)),
"library" => Some(("library", 13)),
"restaurant" | "food_court" => Some(("restaurant", 15)),
"fast_food" => Some(("fast_food", 15)),
"cafe" => Some(("cafe", 15)),
"bar" | "pub" => Some(("bar", 15)),
"supermarket" | "mall" | "department_store" | "marketplace" => Some(("supermarket", 14)),
"convenience" | "shop" => Some(("convenience", 15)),
"museum" | "gallery" => Some(("museum", 13)),
"theater" | "cinema" => Some(("theatre", 13)),
"stadium" | "sports_centre" => Some(("stadium", 13)),
"park" | "playground" | "nature_reserve" => Some(("park", 13)),
"garden" => Some(("garden", 13)),
"zoo" => Some(("zoo", 13)),
"town_hall" | "city_hall" | "government" | "courthouse" | "embassy" => {
Some(("townhall", 13))
}
"post_office" => Some(("post_office", 13)),
"place_of_worship" | "temple" | "church" | "mosque" | "synagogue" | "cemetery"
| "memorial" | "monument" => Some(("attraction", 15)),
"hospital" => Some(("hospital", 13)),
"clinic" | "doctor" | "pharmacy" | "dentist" => Some(("hospital", 15)),
"hotel" | "motel" | "hostel" | "guest_house" | "resort" => Some(("lodging", 15)),
"bank" | "atm" => Some(("bank", 15)),
"police" | "fire_station" => Some(("police", 13)),
"parking" | "fuel" | "charging_station" | "car_wash" | "car_rental" => Some(("fuel", 15)),
_ => None,
}
}
pub fn process(feature: &InputFeature) -> Option<ProcessedFeature> {
match &feature.source {
DataSource::Overture { .. } => process_overture(feature),
DataSource::Osm { .. } => process_osm(feature),
_ => None,
}
}
fn process_overture(feature: &InputFeature) -> Option<ProcessedFeature> {
if let Some(confidence) = feature.get_f64("confidence")
&& confidence < MIN_CONFIDENCE
{
return None;
}
let leaf = feature
.get_str("taxonomy.primary")
.or(feature.get_str("categories.primary"))
.or(feature.get_str("category"));
let basic = feature.get_str("basic_category");
let (kind, min_zoom) = leaf
.and_then(category_to_kind)
.or_else(|| basic.and_then(category_to_kind))?;
let mut properties = Vec::with_capacity(4);
properties.push(("kind".into(), PropValue::Str(kind.into())));
if let Some(detail) = leaf.or(basic) {
properties.push(("kind_detail".into(), PropValue::Str(detail.to_string())));
}
if let Some(confidence) = feature.get_f64("confidence") {
properties.push(("confidence".into(), PropValue::F64(confidence)));
}
push_names(feature, &mut properties);
properties.push(("min_zoom".into(), PropValue::I64(min_zoom as i64)));
Some(ProcessedFeature {
id: feature.id,
geometry: feature.geometry.clone(),
layer: Layer::Pois,
min_zoom,
max_zoom: 15,
sort_rank: 400,
properties,
})
}
fn classify_osm_poi(feature: &InputFeature) -> Option<(&'static str, String, u8)> {
if let Some(aeroway) = feature.get_str("aeroway")
&& aeroway == "aerodrome"
{
return Some(("aerodrome", "aerodrome".into(), 10));
}
if let Some(railway) = feature.get_str("railway")
&& (railway == "station" || railway == "halt")
{
return Some(("station", railway.to_string(), 12));
}
if feature.has_tag("highway", "bus_stop") {
return Some(("bus_stop", "bus_stop".into(), 14));
}
if let Some(natural) = feature.get_str("natural") {
return match natural {
"peak" => Some(("peak", "peak".into(), 11)),
"beach" => Some(("beach", "beach".into(), 13)),
_ => None,
};
}
if let Some(boundary) = feature.get_str("boundary")
&& (boundary == "national_park" || boundary == "protected_area")
{
let protect_class = feature.get_str("protect_class").unwrap_or("");
return match protect_class {
"2" => Some(("park", "national_park".into(), 11)),
_ => Some(("park", boundary.to_string(), 13)),
};
}
if let Some(amenity) = feature.get_str("amenity") {
let kind = match amenity {
"hospital" | "clinic" | "doctors" => "hospital",
"pharmacy" => "pharmacy",
"school" | "kindergarten" => "school",
"university" | "college" => "university",
"library" => "library",
"place_of_worship" => "attraction",
"restaurant" => "restaurant",
"fast_food" => "fast_food",
"cafe" => "cafe",
"bar" | "pub" | "biergarten" => "bar",
"bank" | "atm" => "bank",
"post_office" => "post_office",
"police" => "police",
"fire_station" => "fire_station",
"fuel" => "fuel",
"parking" => "parking",
"theatre" | "cinema" => "theatre",
"townhall" | "community_centre" => "townhall",
"grave_yard" => "cemetery",
"bench" => "bench",
"toilets" => "toilets",
"drinking_water" => "drinking_water",
_ => "other",
};
return Some((kind, amenity.to_string(), 14));
}
if let Some(tourism) = feature.get_str("tourism") {
if tourism == "yes" || tourism == "historic" || tourism == "district" {
return None;
}
let kind = match tourism {
"hotel" | "motel" | "hostel" | "guest_house" => "hotel",
"camp_site" | "caravan_site" => "camp_site",
"museum" => "museum",
"attraction" | "viewpoint" => "attraction",
"information" => "information",
"artwork" | "gallery" => "artwork",
_ => "attraction",
};
return Some((kind, tourism.to_string(), 14));
}
if let Some(historic) = feature.get_str("historic") {
return Some(("historic", historic.to_string(), 14));
}
if let Some(shop) = feature.get_str("shop") {
let kind = match shop {
"supermarket" => "supermarket",
"convenience" | "general" => "convenience",
"books" | "stationery" => "books",
"beauty" | "hairdresser" | "cosmetics" => "beauty",
"electronics" | "computer" | "mobile_phone" | "hifi" => "electronics",
"clothes" | "fashion" | "shoes" | "boutique" | "jewelry" => "clothes",
_ => "convenience",
};
return Some((kind, shop.to_string(), 14));
}
if let Some(leisure) = feature.get_str("leisure") {
let kind = match leisure {
"park" | "nature_reserve" => "park",
"garden" => "garden",
"playground" => "playground",
"sports_centre" | "stadium" | "pitch" => "stadium",
"swimming_pool" => "swimming_pool",
_ => "leisure",
};
return Some((kind, leisure.to_string(), 14));
}
if feature.has_key("craft") {
let craft = feature.get_str("craft").unwrap_or("other");
return Some(("craft", craft.to_string(), 14));
}
if let Some(landuse) = feature.get_str("landuse") {
return match landuse {
"cemetery" => Some(("cemetery", "cemetery".into(), 13)),
"recreation_ground" | "village_green" => {
Some(("recreation_ground", landuse.to_string(), 14))
}
"quarry" => Some(("quarry", "quarry".into(), 14)),
"military" => Some(("military", "military".into(), 14)),
"forest" => {
let is_national_forest = feature
.get_str("operator:type")
.is_some_and(|v| v == "federal" || v == "national");
if is_national_forest {
Some(("forest", "forest".into(), 11))
} else {
None
}
}
_ => None,
};
}
if feature.has_key("attraction") {
let attraction = feature.get_str("attraction").unwrap_or("other");
return Some(("attraction", attraction.to_string(), 14));
}
None
}
fn process_osm(feature: &InputFeature) -> Option<ProcessedFeature> {
if !feature.is_point() {
return None;
}
let (kind, kind_detail, base_zoom) = classify_osm_poi(feature)?;
let output_min_zoom = base_zoom.saturating_add(1);
let mut properties = Vec::with_capacity(6);
properties.push(("kind".into(), PropValue::Str(kind.into())));
properties.push(("kind_detail".into(), PropValue::Str(kind_detail.clone())));
push_names(feature, &mut properties);
properties.push(("min_zoom".into(), PropValue::I64(output_min_zoom as i64)));
if let Some(ele) = feature.get_str("ele")
&& let Ok(elevation) = ele.parse::<f64>()
{
properties.push(("elevation".into(), PropValue::F64(elevation)));
}
if let Some(iata) = feature.get_str("iata") {
properties.push(("iata".into(), PropValue::Str(iata.to_string())));
}
if kind_detail == "place_of_worship"
&& let Some(religion) = feature.get_str("religion")
{
properties.push(("religion".into(), PropValue::Str(religion.to_string())));
}
if kind == "stadium"
&& let Some(sport) = feature.get_str("sport")
{
properties.push(("sport".into(), PropValue::Str(sport.to_string())));
}
if matches!(kind, "restaurant" | "fast_food" | "cafe" | "bar")
&& let Some(cuisine) = feature.get_str("cuisine")
{
properties.push(("cuisine".into(), PropValue::Str(cuisine.to_string())));
}
Some(ProcessedFeature {
id: feature.id,
geometry: feature.geometry.clone(),
layer: Layer::Pois,
min_zoom: output_min_zoom,
max_zoom: 15,
sort_rank: 400,
properties,
})
}
#[cfg(test)]
mod tests {
use super::*;
use crate::source::input::{DataSource, OsmElementType};
use std::collections::HashMap;
use std::sync::Arc;
fn make_overture_feature(props: &[(&str, PropValue)]) -> InputFeature {
let mut properties = HashMap::new();
for (k, v) in props {
properties.insert(k.to_string(), v.clone());
}
InputFeature {
id: 1,
geometry: Arc::new(geo::Geometry::Point(geo::Point::new(13.40, 52.52))),
properties,
bbox: None,
source: DataSource::Overture {
theme: String::new(),
otype: String::new(),
},
}
}
fn make_osm_point(tags: &[(&str, &str)]) -> InputFeature {
let mut properties = HashMap::new();
for (k, v) in tags {
properties.insert(k.to_string(), PropValue::Str(v.to_string()));
}
InputFeature {
id: 100,
geometry: Arc::new(geo::Geometry::Point(geo::Point::new(13.40, 52.52))),
properties,
bbox: None,
source: DataSource::Osm {
element_type: OsmElementType::Node,
relations: vec![],
},
}
}
fn prop(result: &ProcessedFeature, key: &str) -> Option<PropValue> {
result
.properties
.iter()
.find(|(k, _)| k == key)
.map(|(_, v)| v.clone())
}
#[test]
fn schema_v2_taxonomy_primary_sets_the_kind() {
let feat = make_overture_feature(&[
("taxonomy.primary", PropValue::Str("cafe".into())),
("basic_category", PropValue::Str("cafe".into())),
("confidence", PropValue::F64(0.9)),
]);
let result = process(&feat).expect("poi");
assert_eq!(prop(&result, "kind"), Some(PropValue::Str("cafe".into())));
assert_eq!(result.min_zoom, 15);
}
#[test]
fn an_unmapped_leaf_falls_back_to_basic_category() {
let feat = make_overture_feature(&[
(
"taxonomy.primary",
PropValue::Str("italian_restaurant".into()),
),
("basic_category", PropValue::Str("restaurant".into())),
("confidence", PropValue::F64(0.9)),
]);
let result = process(&feat).expect("poi");
assert_eq!(
prop(&result, "kind"),
Some(PropValue::Str("restaurant".into()))
);
assert_eq!(
prop(&result, "kind_detail"),
Some(PropValue::Str("italian_restaurant".into()))
);
}
#[test]
fn taxonomy_wins_over_the_legacy_categories_column() {
let feat = make_overture_feature(&[
("taxonomy.primary", PropValue::Str("airport".into())),
("categories.primary", PropValue::Str("restaurant".into())),
("confidence", PropValue::F64(0.9)),
]);
let result = process(&feat).expect("poi");
assert_eq!(
prop(&result, "kind"),
Some(PropValue::Str("aerodrome".into()))
);
}
#[test]
fn neither_leaf_nor_basic_category_mapped_is_dropped() {
let feat = make_overture_feature(&[
(
"taxonomy.primary",
PropValue::Str("attorney_or_law_firm".into()),
),
(
"basic_category",
PropValue::Str("professional_service".into()),
),
("confidence", PropValue::F64(0.9)),
]);
assert!(process(&feat).is_none());
let unknown = make_overture_feature(&[
(
"categories.primary",
PropValue::Str("something_weird".into()),
),
("confidence", PropValue::F64(0.8)),
]);
assert!(process(&unknown).is_none());
let uncategorised = make_overture_feature(&[("confidence", PropValue::F64(0.8))]);
assert!(process(&uncategorised).is_none());
}
#[test]
fn overture_restaurant_kind() {
let feat = make_overture_feature(&[
("categories.primary", PropValue::Str("restaurant".into())),
("confidence", PropValue::F64(0.9)),
]);
let result = process(&feat).unwrap();
assert_eq!(result.layer, Layer::Pois);
assert_eq!(result.min_zoom, 15);
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind" && *v == PropValue::Str("restaurant".into()))
);
}
#[test]
fn overture_low_confidence_filtered_out() {
let feat = make_overture_feature(&[
("categories.primary", PropValue::Str("restaurant".into())),
("confidence", PropValue::F64(0.5)),
]);
assert!(process(&feat).is_none());
}
#[test]
fn overture_airport_maps_to_aerodrome() {
let feat = make_overture_feature(&[
("categories.primary", PropValue::Str("airport".into())),
("confidence", PropValue::F64(0.95)),
]);
let result = process(&feat).unwrap();
assert_eq!(result.min_zoom, 10);
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind" && *v == PropValue::Str("aerodrome".into()))
);
}
#[test]
fn overture_unrecognised_category_filtered_out() {
let feat = make_overture_feature(&[(
"categories.primary",
PropValue::Str("unicorn_stable".into()),
)]);
assert!(
process(&feat).is_none(),
"a category with no kind mapping yields no POI"
);
}
#[test]
fn overture_reads_the_singular_category_alias() {
let feat = make_overture_feature(&[("category", PropValue::Str("restaurant".into()))]);
let processed = process(&feat).expect("the singular alias is accepted");
assert_eq!(processed.layer, Layer::Pois);
}
#[test]
fn osm_aerodrome_with_iata() {
let feat = make_osm_point(&[
("aeroway", "aerodrome"),
("name", "Berlin Brandenburg"),
("iata", "BER"),
]);
let result = process(&feat).unwrap();
assert_eq!(result.layer, Layer::Pois);
assert_eq!(result.min_zoom, 11);
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind" && *v == PropValue::Str("aerodrome".into()))
);
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "iata" && *v == PropValue::Str("BER".into()))
);
}
#[test]
fn osm_peak_with_elevation() {
let feat = make_osm_point(&[
("natural", "peak"),
("name", "Mount Everest"),
("ele", "8848.86"),
]);
let result = process(&feat).unwrap();
assert_eq!(result.min_zoom, 12);
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind" && *v == PropValue::Str("peak".into()))
);
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "elevation" && *v == PropValue::F64(8848.86))
);
}
#[test]
fn osm_restaurant_with_cuisine() {
let feat = make_osm_point(&[
("amenity", "restaurant"),
("name", "Curry House"),
("cuisine", "indian"),
]);
let result = process(&feat).unwrap();
assert_eq!(result.min_zoom, 15);
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind" && *v == PropValue::Str("restaurant".into()))
);
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "cuisine" && *v == PropValue::Str("indian".into()))
);
}
#[test]
fn osm_bus_stop() {
let feat = make_osm_point(&[("highway", "bus_stop"), ("name", "Main St")]);
let result = process(&feat).unwrap();
assert_eq!(result.min_zoom, 15);
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind" && *v == PropValue::Str("bus_stop".into()))
);
}
#[test]
fn osm_national_park() {
let feat = make_osm_point(&[
("boundary", "national_park"),
("protect_class", "2"),
("name", "Yellowstone"),
]);
let result = process(&feat).unwrap();
assert_eq!(result.min_zoom, 12);
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind" && *v == PropValue::Str("park".into()))
);
}
#[test]
fn osm_shop() {
let feat = make_osm_point(&[("shop", "bakery"), ("name", "Fresh Bread")]);
let result = process(&feat).unwrap();
assert_eq!(result.min_zoom, 15);
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind" && *v == PropValue::Str("convenience".into()))
);
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind_detail" && *v == PropValue::Str("bakery".into()))
);
}
#[test]
fn osm_tourism_hotel() {
let feat = make_osm_point(&[("tourism", "hotel"), ("name", "Grand Hotel")]);
let result = process(&feat).unwrap();
assert_eq!(result.min_zoom, 15);
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind" && *v == PropValue::Str("hotel".into()))
);
}
#[test]
fn osm_non_point_skipped() {
let mut properties = HashMap::new();
properties.insert(
"amenity".to_string(),
PropValue::Str("restaurant".to_string()),
);
let feat = InputFeature {
id: 200,
geometry: Arc::new(geo::Geometry::LineString(geo::LineString::from(vec![
(0.0, 0.0),
(1.0, 1.0),
]))),
properties,
bbox: None,
source: DataSource::Osm {
element_type: OsmElementType::Way,
relations: vec![],
},
};
assert!(process(&feat).is_none());
}
#[test]
fn ne_source_returns_none() {
let feat = InputFeature {
id: 300,
geometry: Arc::new(geo::Geometry::Point(geo::Point::new(0.0, 0.0))),
properties: HashMap::new(),
bbox: None,
source: DataSource::NaturalEarth {
source_layer: "ne_10m_land".to_string(),
},
};
assert!(process(&feat).is_none());
}
#[test]
fn osm_place_of_worship_with_religion() {
let feat = make_osm_point(&[
("amenity", "place_of_worship"),
("religion", "buddhism"),
("name", "Temple"),
]);
let result = process(&feat).unwrap();
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind" && *v == PropValue::Str("attraction".into()))
);
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "religion" && *v == PropValue::Str("buddhism".into()))
);
}
#[test]
fn osm_historic_feature() {
let feat = make_osm_point(&[("historic", "castle"), ("name", "Old Castle")]);
let result = process(&feat).unwrap();
assert_eq!(result.min_zoom, 15);
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind" && *v == PropValue::Str("historic".into()))
);
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind_detail" && *v == PropValue::Str("castle".into()))
);
}
#[test]
fn land_polygons_source_returns_none() {
let feat = InputFeature {
id: 400,
geometry: Arc::new(geo::Geometry::Point(geo::Point::new(0.0, 0.0))),
properties: HashMap::new(),
bbox: None,
source: DataSource::LandPolygons,
};
assert!(process(&feat).is_none());
}
#[test]
fn overture_no_confidence_passes() {
let feat =
make_overture_feature(&[("categories.primary", PropValue::Str("restaurant".into()))]);
let result = process(&feat).unwrap();
assert_eq!(result.min_zoom, 15);
}
#[test]
fn overture_category_field_fallback() {
let feat = make_overture_feature(&[
("category", PropValue::Str("cafe".into())),
("confidence", PropValue::F64(0.9)),
]);
let result = process(&feat).unwrap();
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind" && *v == PropValue::Str("cafe".into()))
);
}
#[test]
fn overture_name_field_extracted() {
let feat = make_overture_feature(&[
("categories.primary", PropValue::Str("cafe".into())),
("confidence", PropValue::F64(0.9)),
("names.primary", PropValue::Str("Joe's".into())),
]);
let result = process(&feat).unwrap();
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "name" && *v == PropValue::Str("Joe's".into()))
);
}
fn has(r: &ProcessedFeature, key: &str, value: &str) -> bool {
r.properties
.iter()
.any(|(k, v)| k == key && *v == PropValue::Str(value.into()))
}
#[test]
fn osm_poi_carries_script_and_name_en() {
let r = process(&make_osm_point(&[
("tourism", "hotel"),
("name", "होटल ताज"),
("name:en", "Taj Hotel"),
]))
.unwrap();
assert!(has(&r, "name", "होटल ताज"));
assert!(has(&r, "script", "Devanagari"));
assert!(has(&r, "name:en", "Taj Hotel"));
}
#[test]
fn overture_poi_takes_name_en_from_the_common_names() {
let r = process(&make_overture_feature(&[
("categories.primary", PropValue::Str("cafe".into())),
("confidence", PropValue::F64(0.9)),
("names.primary", PropValue::Str("咖啡馆".into())),
("names.common.en", PropValue::Str("Coffee House".into())),
]))
.unwrap();
assert!(has(&r, "name", "咖啡馆"));
assert!(has(&r, "script", "Han"));
assert!(has(&r, "name:en", "Coffee House"));
}
#[test]
fn overture_name_falls_back_to_name_field() {
let feat = make_overture_feature(&[
("categories.primary", PropValue::Str("cafe".into())),
("name", PropValue::Str("Plain Name".into())),
]);
let result = process(&feat).unwrap();
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "name" && *v == PropValue::Str("Plain Name".into()))
);
}
#[test]
fn overture_confidence_property_set() {
let feat = make_overture_feature(&[
("categories.primary", PropValue::Str("cafe".into())),
("confidence", PropValue::F64(0.85)),
]);
let result = process(&feat).unwrap();
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "confidence" && *v == PropValue::F64(0.85))
);
}
#[test]
fn overture_category_to_kind_full_coverage() {
let cases: &[(&str, &str, u8)] = &[
("airport", "aerodrome", 10),
("train_station", "station", 12),
("bus_station", "bus_stop", 14),
("ferry_terminal", "ferry_terminal", 12),
("school", "school", 13),
("kindergarten", "school", 13),
("university", "university", 13),
("college", "university", 13),
("library", "library", 13),
("restaurant", "restaurant", 15),
("food_court", "restaurant", 15),
("fast_food", "fast_food", 15),
("cafe", "cafe", 15),
("bar", "bar", 15),
("pub", "bar", 15),
("supermarket", "supermarket", 14),
("mall", "supermarket", 14),
("department_store", "supermarket", 14),
("marketplace", "supermarket", 14),
("convenience", "convenience", 15),
("shop", "convenience", 15),
("museum", "museum", 13),
("gallery", "museum", 13),
("theater", "theatre", 13),
("cinema", "theatre", 13),
("stadium", "stadium", 13),
("sports_centre", "stadium", 13),
("park", "park", 13),
("playground", "park", 13),
("nature_reserve", "park", 13),
("garden", "garden", 13),
("zoo", "zoo", 13),
("town_hall", "townhall", 13),
("city_hall", "townhall", 13),
("government", "townhall", 13),
("courthouse", "townhall", 13),
("embassy", "townhall", 13),
("post_office", "post_office", 13),
("place_of_worship", "attraction", 15),
("temple", "attraction", 15),
("church", "attraction", 15),
("mosque", "attraction", 15),
("synagogue", "attraction", 15),
("cemetery", "attraction", 15),
("memorial", "attraction", 15),
("monument", "attraction", 15),
("hospital", "hospital", 13),
("clinic", "hospital", 15),
("doctor", "hospital", 15),
("pharmacy", "hospital", 15),
("dentist", "hospital", 15),
("hotel", "lodging", 15),
("motel", "lodging", 15),
("hostel", "lodging", 15),
("guest_house", "lodging", 15),
("resort", "lodging", 15),
("bank", "bank", 15),
("atm", "bank", 15),
("police", "police", 13),
("fire_station", "police", 13),
("parking", "fuel", 15),
("fuel", "fuel", 15),
("charging_station", "fuel", 15),
("car_wash", "fuel", 15),
("car_rental", "fuel", 15),
];
for (cat, expected_kind, expected_zoom) in cases {
let feat = make_overture_feature(&[
("categories.primary", PropValue::Str((*cat).into())),
("confidence", PropValue::F64(0.9)),
]);
let result = process(&feat).unwrap_or_else(|| panic!("category {cat} not mapped"));
assert_eq!(result.min_zoom, *expected_zoom, "category {cat}");
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind" && *v == PropValue::Str((*expected_kind).into())),
"category {cat} → expected kind {expected_kind}",
);
}
}
#[test]
fn osm_railway_halt() {
for railway in ["station", "halt"] {
let feat = make_osm_point(&[("railway", railway), ("name", "Central")]);
let result = process(&feat).expect(railway);
assert_eq!(result.min_zoom, 13, "{railway}");
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind" && *v == PropValue::Str("station".into())),
"{railway}"
);
}
}
#[test]
fn osm_railway_unrelated_returns_none() {
let feat = make_osm_point(&[("railway", "switch")]);
assert!(process(&feat).is_none());
}
#[test]
fn osm_natural_beach() {
let feat = make_osm_point(&[("natural", "beach")]);
let result = process(&feat).unwrap();
assert_eq!(result.min_zoom, 14);
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind" && *v == PropValue::Str("beach".into()))
);
}
#[test]
fn osm_natural_other_returns_none() {
let feat = make_osm_point(&[("natural", "tree")]);
assert!(process(&feat).is_none());
}
#[test]
fn osm_protected_area_default() {
let feat = make_osm_point(&[("boundary", "protected_area")]);
let result = process(&feat).unwrap();
assert_eq!(result.min_zoom, 14);
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind_detail" && *v == PropValue::Str("protected_area".into()))
);
}
#[test]
fn osm_amenity_full_coverage() {
let cases: &[(&str, &str)] = &[
("hospital", "hospital"),
("clinic", "hospital"),
("doctors", "hospital"),
("pharmacy", "pharmacy"),
("school", "school"),
("kindergarten", "school"),
("university", "university"),
("college", "university"),
("library", "library"),
("place_of_worship", "attraction"),
("fast_food", "fast_food"),
("cafe", "cafe"),
("pub", "bar"),
("biergarten", "bar"),
("atm", "bank"),
("post_office", "post_office"),
("police", "police"),
("fire_station", "fire_station"),
("fuel", "fuel"),
("parking", "parking"),
("theatre", "theatre"),
("cinema", "theatre"),
("townhall", "townhall"),
("community_centre", "townhall"),
("grave_yard", "cemetery"),
("bench", "bench"),
("toilets", "toilets"),
("drinking_water", "drinking_water"),
("weird_amenity_unknown", "other"),
];
for (amenity, expected_kind) in cases {
let feat = make_osm_point(&[("amenity", *amenity)]);
let result = process(&feat).unwrap_or_else(|| panic!("amenity {amenity}"));
assert_eq!(result.min_zoom, 15, "amenity {amenity}");
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind" && *v == PropValue::Str((*expected_kind).into())),
"amenity {amenity} → expected kind {expected_kind}",
);
}
}
#[test]
fn osm_tourism_full_coverage() {
let cases: &[(&str, &str)] = &[
("motel", "hotel"),
("hostel", "hotel"),
("guest_house", "hotel"),
("camp_site", "camp_site"),
("caravan_site", "camp_site"),
("museum", "museum"),
("attraction", "attraction"),
("viewpoint", "attraction"),
("information", "information"),
("artwork", "artwork"),
("gallery", "artwork"),
("zoo", "attraction"),
];
for (tourism, expected_kind) in cases {
let feat = make_osm_point(&[("tourism", *tourism)]);
let result = process(&feat).unwrap_or_else(|| panic!("tourism {tourism}"));
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind" && *v == PropValue::Str((*expected_kind).into())),
"tourism {tourism}",
);
}
}
#[test]
fn osm_tourism_yes_filtered() {
for v in ["yes", "historic", "district"] {
let feat = make_osm_point(&[("tourism", v)]);
assert!(process(&feat).is_none(), "tourism={v} should be filtered");
}
}
#[test]
fn osm_shop_full_coverage() {
let cases: &[(&str, &str)] = &[
("supermarket", "supermarket"),
("convenience", "convenience"),
("general", "convenience"),
("books", "books"),
("stationery", "books"),
("beauty", "beauty"),
("hairdresser", "beauty"),
("cosmetics", "beauty"),
("electronics", "electronics"),
("computer", "electronics"),
("mobile_phone", "electronics"),
("hifi", "electronics"),
("clothes", "clothes"),
("fashion", "clothes"),
("shoes", "clothes"),
("boutique", "clothes"),
("jewelry", "clothes"),
("unknown_shop_thing", "convenience"),
];
for (shop, expected_kind) in cases {
let feat = make_osm_point(&[("shop", *shop)]);
let result = process(&feat).unwrap_or_else(|| panic!("shop {shop}"));
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind" && *v == PropValue::Str((*expected_kind).into())),
"shop {shop} → {expected_kind}",
);
}
}
#[test]
fn osm_leisure_full_coverage() {
let cases: &[(&str, &str)] = &[
("park", "park"),
("nature_reserve", "park"),
("garden", "garden"),
("playground", "playground"),
("sports_centre", "stadium"),
("stadium", "stadium"),
("pitch", "stadium"),
("swimming_pool", "swimming_pool"),
("fitness_centre", "leisure"),
];
for (leisure, expected_kind) in cases {
let feat = make_osm_point(&[("leisure", *leisure)]);
let result = process(&feat).unwrap_or_else(|| panic!("leisure {leisure}"));
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind" && *v == PropValue::Str((*expected_kind).into())),
"leisure {leisure}",
);
}
}
#[test]
fn osm_stadium_with_sport() {
let feat = make_osm_point(&[("leisure", "stadium"), ("sport", "soccer")]);
let result = process(&feat).unwrap();
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "sport" && *v == PropValue::Str("soccer".into()))
);
}
#[test]
fn osm_craft_with_value() {
let feat = make_osm_point(&[("craft", "carpenter")]);
let result = process(&feat).unwrap();
assert_eq!(result.min_zoom, 15);
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind" && *v == PropValue::Str("craft".into()))
);
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind_detail" && *v == PropValue::Str("carpenter".into()))
);
}
#[test]
fn osm_landuse_cemetery() {
let feat = make_osm_point(&[("landuse", "cemetery")]);
let result = process(&feat).unwrap();
assert_eq!(result.min_zoom, 14);
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind" && *v == PropValue::Str("cemetery".into()))
);
}
#[test]
fn osm_landuse_recreation_ground() {
for v in ["recreation_ground", "village_green"] {
let feat = make_osm_point(&[("landuse", v)]);
let result = process(&feat).unwrap();
assert!(
result
.properties
.iter()
.any(|(k, val)| k == "kind"
&& *val == PropValue::Str("recreation_ground".into())),
"landuse {v}",
);
}
}
#[test]
fn osm_landuse_quarry() {
let feat = make_osm_point(&[("landuse", "quarry")]);
let result = process(&feat).unwrap();
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind" && *v == PropValue::Str("quarry".into()))
);
}
#[test]
fn osm_landuse_military() {
let feat = make_osm_point(&[("landuse", "military")]);
let result = process(&feat).unwrap();
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind" && *v == PropValue::Str("military".into()))
);
}
#[test]
fn osm_landuse_forest_national() {
for operator in ["national", "federal"] {
let feat = make_osm_point(&[("landuse", "forest"), ("operator:type", operator)]);
let result = process(&feat).expect(operator);
assert_eq!(result.min_zoom, 12, "{operator}");
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind" && *v == PropValue::Str("forest".into())),
"{operator}"
);
}
}
#[test]
fn osm_landuse_forest_non_national_returns_none() {
let feat = make_osm_point(&[("landuse", "forest")]);
assert!(process(&feat).is_none());
}
#[test]
fn osm_landuse_other_returns_none() {
let feat = make_osm_point(&[("landuse", "residential")]);
assert!(process(&feat).is_none());
}
#[test]
fn osm_attraction_tag() {
let feat = make_osm_point(&[("attraction", "roller_coaster")]);
let result = process(&feat).unwrap();
assert_eq!(result.min_zoom, 15);
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind" && *v == PropValue::Str("attraction".into()))
);
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "kind_detail" && *v == PropValue::Str("roller_coaster".into()))
);
}
#[test]
fn osm_peak_invalid_elevation_skipped() {
let feat = make_osm_point(&[("natural", "peak"), ("ele", "not-a-number")]);
let result = process(&feat).unwrap();
assert!(!result.properties.iter().any(|(k, _)| k == "elevation"));
}
#[test]
fn osm_food_cuisine_for_each_kind() {
for kind_amenity in ["restaurant", "fast_food", "cafe", "bar"] {
let feat = make_osm_point(&[("amenity", kind_amenity), ("cuisine", "italian")]);
let result = process(&feat).unwrap();
assert!(
result
.properties
.iter()
.any(|(k, v)| k == "cuisine" && *v == PropValue::Str("italian".into())),
"amenity {kind_amenity}",
);
}
}
#[test]
fn osm_aerodrome_no_iata() {
let feat = make_osm_point(&[("aeroway", "aerodrome")]);
let result = process(&feat).unwrap();
assert!(!result.properties.iter().any(|(k, _)| k == "iata"));
}
#[test]
fn osm_aeroway_other_value_falls_through() {
assert!(process(&make_osm_point(&[("aeroway", "runway")])).is_none());
assert!(process(&make_osm_point(&[("name", "no idea")])).is_none());
}
#[test]
fn osm_no_name() {
let feat = make_osm_point(&[("amenity", "restaurant")]);
let result = process(&feat).unwrap();
assert!(!result.properties.iter().any(|(k, _)| k == "name"));
}
}