Coverage for src/overturetoosm/buildings.py: 100%
23 statements
« prev ^ index » next coverage.py v7.6.0, created at 2024-07-28 10:12 -0400
« prev ^ index » next coverage.py v7.6.0, created at 2024-07-28 10:12 -0400
1"""Convert Overture's `buildings` features to OSM tags."""
3from typing import Dict
4from .utils import source_statement
5from .objects import BuildingProps, ConfidenceError
8def process_building(
9 props: dict,
10 confidence: float = 0.0,
11) -> Dict[str, str]:
12 """Convert Overture's building properties to OSM tags.
14 Args:
15 props (dict): The feature properties from the Overture GeoJSON.
16 confidence (float, optional): The minimum confidence level. Defaults to 0.0.
18 Returns:
19 Dict[str, str]: The reshaped and converted properties in OSM's flat str:str schema.
21 Raises:
22 `ConfidenceError`: Raised if the confidence level is set above a feature's confidence.
23 """
24 new_props = {}
25 prop_obj = BuildingProps(**props)
26 confidences = [source.confidence for source in prop_obj.sources]
27 if any(conf < confidence for conf in confidences):
28 raise ConfidenceError(confidence, max(confidences))
30 new_props["building"] = prop_obj.class_
32 new_props["source"] = source_statement(prop_obj.sources)
34 obj_dict = prop_obj.model_dump(exclude_none=True).items()
35 new_props.update(
36 {
37 k.replace("facade", "building")
38 .replace("_", ":")
39 .replace("color", "colour"): v
40 for k, v in obj_dict
41 if k.startswith(("roof", "facade"))
42 }
43 )
44 new_props.update({k: v for k, v in obj_dict if k.endswith("height")})
46 if prop_obj.is_underground:
47 new_props["location"] = "underground"
48 if prop_obj.num_floors:
49 new_props["building:levels"] = prop_obj.num_floors
50 if prop_obj.num_floors_underground:
51 new_props["building:levels:underground"] = prop_obj.num_floors_underground
52 if prop_obj.min_floor:
53 new_props["building:min_level"] = prop_obj.min_floor
54 return new_props