overturetoosm
Convert Overture's places
, buildings
, and addresses
features to OSM tags.
overturetoosm
is a Python package to convert objects tagged in the
Overture schema for use in OSM. Only Overture's places
, buildings
,
and addresses
layers are currently supported.
Links:
The package also allows you to use the module directly from the command line.
With the overturemaps
Python package installed, you can download and convert
Overture data to OSM in two lines of code.
$ python -m overturemaps download --bbox=-71.068,42.353,-71.058,42.363 \\
-f geojson --type=place -o boston.geojson
$ python -m overturetoosm place -i boston.geojson --in-place --confidence 0.9
1r"""Convert Overture's `places`, `buildings`, and `addresses` features to OSM tags. 2 3`overturetoosm` is a Python package to convert objects tagged in the 4Overture schema for use in OSM. Only Overture's `places`, `buildings`, 5and `addresses` layers are currently supported. 6 7Links: 8* [Project GitHub](https://github.com/whubsch/overturetoosm) 9* [Documentation](https://whubsch.github.io/overturetoosm/) 10* [PyPI](https://pypi.org/project/overturetoosm/) 11 12The package also allows you to use the module directly from the command line. 13With the `overturemaps` Python package installed, you can download and convert 14Overture data to OSM in two lines of code. 15 16```bash 17$ python -m overturemaps download --bbox=-71.068,42.353,-71.058,42.363 \\ 18 -f geojson --type=place -o boston.geojson 19$ python -m overturetoosm place -i boston.geojson --in-place --confidence 0.9 20``` 21""" 22 23from . import addresses, buildings, objects, places, resources, segments, utils 24from .addresses import process_address 25from .buildings import process_building 26from .places import process_place 27from .utils import process_geojson 28 29__all__ = [ 30 "process_place", 31 "process_building", 32 "process_address", 33 "process_geojson", 34 "places", 35 "buildings", 36 "addresses", 37 "objects", 38 "segments", 39 "utils", 40 "resources", 41]
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
region
tag 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
type
key, 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 ifunmatched
is set toerror
and the Overture category has no OSM definition.overturetoosm.objects.ConfidenceError
: Raised if the confidence level is set above a feature's confidence.
9def process_building(props: dict, confidence: float = 0.0) -> Dict[str, str]: 10 """Convert Overture's building properties to OSM tags. 11 12 Args: 13 props (dict): The feature properties from the Overture GeoJSON. 14 confidence (float, optional): The minimum confidence level. Defaults to 0.0. 15 16 Returns: 17 Dict[str, str]: The reshaped and converted properties in OSM's flat 18 str:str schema. 19 20 Raises: 21 `overturetoosm.objects.ConfidenceError`: Raised if the confidence level is set 22 above a feature's confidence. 23 """ 24 return BuildingProps(**props).to_osm(confidence)
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.
9def process_address(props: dict, style: str = "US") -> Dict[str, str]: 10 """Convert Overture's address properties to OSM tags. 11 12 Args: 13 props (dict): The feature properties from the Overture GeoJSON. 14 style (str, optional): How to handle the `address_levels` field. Open 15 a pull request or issue to add support for other regions. Defaults to "US". 16 17 Returns: 18 Dict[str, str]: The reshaped and converted properties in OSM's flat 19 str:str schema. 20 """ 21 return AddressProps(**props).to_osm(style)
Convert Overture's address properties to OSM tags.
Arguments:
- props (dict): The feature properties from the Overture GeoJSON.
- style (str, optional): How to handle the
address_levels
field. Open a pull request or issue to add support for other regions. Defaults to "US".
Returns:
Dict[str, str]: The reshaped and converted properties in OSM's flat str:str schema.
9def process_geojson( 10 geojson: dict, 11 fx: Callable, 12 confidence: Optional[float] = None, 13 options: Optional[dict] = None, 14) -> dict: 15 """Convert an Overture `place` GeoJSON to one that follows OSM's schema. 16 17 Example usage: 18 ```python 19 import json 20 from overturetoosm import process_geojson 21 22 with open("overture.geojson", "r", encoding="utf-8") as f: 23 contents: dict = json.load(f) 24 geojson = process_geojson(contents, fx=process_building) 25 26 with open("overture_out.geojson", "w+", encoding="utf-8") as x: 27 json.dump(geojson, x, indent=4) 28 ``` 29 Args: 30 geojson (dict): The dictionary representation of the Overture GeoJSON. 31 fx (Callable): The function to apply to each feature. 32 confidence (float, optional): The minimum confidence level. Defaults to 0.0. 33 options (dict, optional): Function-specific options to pass as arguments to 34 the `fx` function. 35 36 Returns: 37 dict: The dictionary representation of the GeoJSON that follows OSM's schema. 38 """ 39 options = options or {} 40 new_features = [] 41 for feature in geojson["features"]: 42 try: 43 if confidence: 44 feature["properties"] = fx(feature["properties"], confidence, **options) 45 else: 46 feature["properties"] = fx(feature["properties"], **options) 47 new_features.append(feature) 48 except (ConfidenceError, UnmatchedError): 49 pass 50 51 geojson["features"] = new_features 52 return geojson
Convert an Overture place
GeoJSON to one that follows OSM's schema.
Example usage:
import json
from overturetoosm import process_geojson
with open("overture.geojson", "r", encoding="utf-8") as f:
contents: dict = json.load(f)
geojson = process_geojson(contents, fx=process_building)
with open("overture_out.geojson", "w+", encoding="utf-8") as x:
json.dump(geojson, x, indent=4)
Arguments:
- geojson (dict): The dictionary representation of the Overture GeoJSON.
- fx (Callable): The function to apply to each feature.
- confidence (float, optional): The minimum confidence level. Defaults to 0.0.
- options (dict, optional): Function-specific options to pass as arguments to
the
fx
function.
Returns:
dict: The dictionary representation of the GeoJSON that follows OSM's schema.