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.

$ 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$ 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]
def process_place( props: dict, confidence: float = 0.0, region_tag: str = 'addr:state', unmatched: Literal['error', 'force', 'ignore'] = 'ignore', required_license: str | None = 'CDLA') -> 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    required_license: str | None = "CDLA",
15) -> dict[str, str]:
16    """Convert Overture's places properties to OSM tags.
17
18    Example usage:
19    ```python
20    import json
21    from overturetoosm import process_place
22
23    with open("overture.geojson", "r", encoding="utf-8") as f:
24        contents: dict = json.load(f)
25
26        for feature in contents["features"]:
27            feature["properties"] = process_place(feature["properties"], confidence=0.5)
28
29    with open("overture_out.geojson", "w+", encoding="utf-8") as x:
30        json.dump(contents, x, indent=4)
31    ```
32    Args:
33        props (dict): The feature properties from the Overture GeoJSON.
34        region_tag (str, optional): What tag to convert Overture's `region` tag to.
35            Defaults to `addr:state`.
36        confidence (float, optional): The minimum confidence level. Defaults to 0.0.
37        unmatched (Literal["error", "force", "ignore"], optional): How to handle
38            unmatched Overture categories. The "error" option raises an UnmatchedError
39            exception, "force" puts the category into the `type` key, and "ignore"
40            only returns other properties. Defaults to "ignore".
41        required_license (str | None, optional): Required license string that must
42            be present in at least one source (e.g., "CDLA"). Features with no
43            matching license will raise a LicenseError. If None, no license
44            validation is performed. Defaults to "CDLA".
45
46    Returns:
47        dict[str, str]: The reshaped and converted properties in OSM's flat str:str
48            schema.
49
50    Raises:
51        `overturetoosm.objects.UnmatchedError`: Raised if `unmatched` is set to `error`
52            and the Overture category has no OSM definition.
53        `overturetoosm.objects.ConfidenceError`: Raised if the confidence level is set
54            above a feature's confidence.
55        `overturetoosm.objects.LicenseError`: Raised if `required_license` is set
56            and no sources contain the required license.
57    """
58    return PlaceProps(**props).to_osm(
59        confidence, region_tag, unmatched, required_license
60    )

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 to addr: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".
  • required_license (str | None, optional): Required license string that must be present in at least one source (e.g., "CDLA"). Features with no matching license will raise a LicenseError. If None, no license validation is performed. Defaults to "CDLA".
Returns:

dict[str, str]: The reshaped and converted properties in OSM's flat str:str schema.

Raises:
def process_building( props: dict, confidence: float = 0.0, required_license: str | None = 'CDLA') -> dict[str, str]:
 7def process_building(
 8    props: dict, confidence: float = 0.0, required_license: str | None = "CDLA"
 9) -> 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        required_license (str | None, optional): Required license string that must
16            be present in at least one source (e.g., "CDLA"). Features with no
17            matching license will raise a LicenseError. If None, no license
18            validation is performed. Defaults to "CDLA".
19
20    Returns:
21        dict[str, str]: The reshaped and converted properties in OSM's flat
22            str:str schema.
23
24    Raises:
25        `overturetoosm.objects.ConfidenceError`: Raised if the confidence level is set
26            above a feature's confidence.
27        `overturetoosm.objects.LicenseError`: Raised if `required_license` is set
28            and no sources contain the required license.
29    """
30    return BuildingProps(**props).to_osm(confidence, required_license)

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.
  • required_license (str | None, optional): Required license string that must be present in at least one source (e.g., "CDLA"). Features with no matching license will raise a LicenseError. If None, no license validation is performed. Defaults to "CDLA".
Returns:

dict[str, str]: The reshaped and converted properties in OSM's flat str:str schema.

Raises:
def process_address( props: dict, style: str = 'US', required_license: str | None = 'CDLA') -> dict[str, str]:
 7def process_address(
 8    props: dict, style: str = "US", required_license: str | None = "CDLA"
 9) -> 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        required_license (str | None, optional): Required license string that must
17            be present in at least one source (e.g., "CDLA"). Features with no
18            matching license will raise a LicenseError. If None, no license
19            validation is performed. Defaults to "CDLA".
20
21    Returns:
22        dict[str, str]: The reshaped and converted properties in OSM's flat
23            str:str schema.
24
25    Raises:
26        `overturetoosm.objects.LicenseError`: Raised if `required_license` is set
27            and no sources contain the required license.
28    """
29    return AddressProps(**props).to_osm(style, required_license)

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".
  • required_license (str | None, optional): Required license string that must be present in at least one source (e.g., "CDLA"). Features with no matching license will raise a LicenseError. If None, no license validation is performed. Defaults to "CDLA".
Returns:

dict[str, str]: The reshaped and converted properties in OSM's flat str:str schema.

Raises:
def process_geojson( geojson: dict, fx: Callable, confidence: float | None = None, options: dict | None = None) -> dict:
 9def process_geojson(
10    geojson: dict,
11    fx: Callable,
12    confidence: float | None = None,
13    options: dict | None = 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, LicenseError):
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.