Coverage for src/overturetoosm/places.py: 100%
4 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-07-22 06:43 -0400
« prev ^ index » next coverage.py v7.6.1, created at 2025-07-22 06:43 -0400
1"""Convert Overture's `places` features to OSM tags."""
3from typing import Literal
5from .objects import PlaceProps
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.
16 Example usage:
17 ```python
18 import json
19 from overturetoosm import process_place
21 with open("overture.geojson", "r", encoding="utf-8") as f:
22 contents: dict = json.load(f)
24 for feature in contents["features"]:
25 feature["properties"] = process_place(feature["properties"], confidence=0.5)
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".
40 Returns:
41 dict[str, str]: The reshaped and converted properties in OSM's flat str:str
42 schema.
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)