overturetoosm.places
Convert Overture's places features to OSM tags.
1"""Convert Overture's `places` features to OSM tags.""" 2 3from typing import Dict, Literal 4 5from .objects import PlaceProps 6 7 8def process_place( 9 props: dict, 10 confidence: float = 0.0, 11 region_tag: str = "addr:state", 12 unmatched: Literal["error", "force", "ignore"] = "ignore", 13) -> Dict[str, str]: 14 """Convert Overture's places properties to OSM tags. 15 16 Example usage: 17 ```python 18 import json 19 from overturetoosm import process_place 20 21 with open("overture.geojson", "r", encoding="utf-8") as f: 22 contents: dict = json.load(f) 23 24 for feature in contents["features"]: 25 feature["properties"] = process_place(feature["properties"], confidence=0.5) 26 27 with open("overture_out.geojson", "w+", encoding="utf-8") as x: 28 json.dump(contents, x, indent=4) 29 ``` 30 Args: 31 props (dict): The feature properties from the Overture GeoJSON. 32 region_tag (str, optional): What tag to convert Overture's `region` tag to. 33 Defaults to `addr:state`. 34 confidence (float, optional): The minimum confidence level. Defaults to 0.0. 35 unmatched (Literal["error", "force", "ignore"], optional): How to handle 36 unmatched Overture categories. The "error" option raises an UnmatchedError 37 exception, "force" puts the category into the `type` key, and "ignore" 38 only returns other properties. Defaults to "ignore". 39 40 Returns: 41 dict[str, str]: The reshaped and converted properties in OSM's flat str:str 42 schema. 43 44 Raises: 45 `overturetoosm.objects.UnmatchedError`: Raised if `unmatched` is set to `error` 46 and the Overture category has no OSM definition. 47 `overturetoosm.objects.ConfidenceError`: Raised if the confidence level is set 48 above a feature's confidence. 49 """ 50 return PlaceProps(**props).to_osm(confidence, region_tag, unmatched)
def
process_place( props: dict, confidence: float = 0.0, region_tag: str = 'addr:state', unmatched: Literal['error', 'force', 'ignore'] = 'ignore') -> Dict[str, str]:
9def process_place( 10 props: dict, 11 confidence: float = 0.0, 12 region_tag: str = "addr:state", 13 unmatched: Literal["error", "force", "ignore"] = "ignore", 14) -> Dict[str, str]: 15 """Convert Overture's places properties to OSM tags. 16 17 Example usage: 18 ```python 19 import json 20 from overturetoosm import process_place 21 22 with open("overture.geojson", "r", encoding="utf-8") as f: 23 contents: dict = json.load(f) 24 25 for feature in contents["features"]: 26 feature["properties"] = process_place(feature["properties"], confidence=0.5) 27 28 with open("overture_out.geojson", "w+", encoding="utf-8") as x: 29 json.dump(contents, x, indent=4) 30 ``` 31 Args: 32 props (dict): The feature properties from the Overture GeoJSON. 33 region_tag (str, optional): What tag to convert Overture's `region` tag to. 34 Defaults to `addr:state`. 35 confidence (float, optional): The minimum confidence level. Defaults to 0.0. 36 unmatched (Literal["error", "force", "ignore"], optional): How to handle 37 unmatched Overture categories. The "error" option raises an UnmatchedError 38 exception, "force" puts the category into the `type` key, and "ignore" 39 only returns other properties. Defaults to "ignore". 40 41 Returns: 42 dict[str, str]: The reshaped and converted properties in OSM's flat str:str 43 schema. 44 45 Raises: 46 `overturetoosm.objects.UnmatchedError`: Raised if `unmatched` is set to `error` 47 and the Overture category has no OSM definition. 48 `overturetoosm.objects.ConfidenceError`: Raised if the confidence level is set 49 above a feature's confidence. 50 """ 51 return PlaceProps(**props).to_osm(confidence, region_tag, unmatched)
Convert Overture's places properties to OSM tags.
Example usage:
import json
from overturetoosm import process_place
with open("overture.geojson", "r", encoding="utf-8") as f:
contents: dict = json.load(f)
for feature in contents["features"]:
feature["properties"] = process_place(feature["properties"], confidence=0.5)
with open("overture_out.geojson", "w+", encoding="utf-8") as x:
json.dump(contents, x, indent=4)
Arguments:
- props (dict): The feature properties from the Overture GeoJSON.
- region_tag (str, optional): What tag to convert Overture's
regiontag to. Defaults toaddr:state. - confidence (float, optional): The minimum confidence level. Defaults to 0.0.
- unmatched (Literal["error", "force", "ignore"], optional): How to handle
unmatched Overture categories. The "error" option raises an UnmatchedError
exception, "force" puts the category into the
typekey, and "ignore" only returns other properties. Defaults to "ignore".
Returns:
dict[str, str]: The reshaped and converted properties in OSM's flat str:str schema.
Raises:
overturetoosm.objects.UnmatchedError: Raised ifunmatchedis set toerrorand the Overture category has no OSM definition.overturetoosm.objects.ConfidenceError: Raised if the confidence level is set above a feature's confidence.