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