Source code for openworld_radio_twin.providers.building_sources

"""Built-in building sources and deterministic, explicitly versioned routing."""

from __future__ import annotations

from openworld_radio_twin.config import Settings
from openworld_radio_twin.licences import (
    ODBL,
    ODBL_URL,
    OSM_ATTRIBUTION,
    OSM_FALLBACK_PROVIDER,
    OSM_LICENSE_URL,
    OVERTURE_ATTRIBUTION,
)
from openworld_radio_twin.providers import berlin, boston
from openworld_radio_twin.providers.base import BuildingQueryResult
from openworld_radio_twin.providers.berlin import BerlinProvider
from openworld_radio_twin.providers.osm import OsmProvider
from openworld_radio_twin.providers.overture import OvertureBuildingProvider
from openworld_radio_twin.providers.registry import (
    BuildingSource,
    BuildingSourceRegistry,
    region,
    resolve_source,
)
from openworld_radio_twin.providers.three_d_bag import (
    ATTRIBUTION,
    LICENSE,
    LICENSE_URL,
    ThreeDBagProvider,
)

GLOBAL_IMPLEMENTATION_VERSION = "overture-osm-v1"


[docs] class OsmBuildingSource: def __init__(self, settings, client): self.provider = OsmProvider(settings, client)
[docs] async def buildings(self, latitude, longitude, radius_m, limit): return BuildingQueryResult( buildings=await self.provider.buildings(latitude, longitude, radius_m, limit=limit), provider=OSM_FALLBACK_PROVIDER, )
[docs] def default_building_sources() -> BuildingSourceRegistry: registry = BuildingSourceRegistry( ( BuildingSource( "boston", "Boston BPDA OBJ", "1", lambda settings, client: boston.BostonProvider(settings, client), auto_covers=region("boston"), auto_priority=100, attribution=boston.ATTRIBUTION, license_url=boston.LICENSE_URL, configuration_identity=boston.configuration_identity, ), BuildingSource( "berlin", "Berlin LoD2", "1", lambda settings, client: BerlinProvider(client), auto_covers=region("berlin"), auto_priority=100, attribution=berlin.ATTRIBUTION, license=berlin.LICENSE, license_url=berlin.LICENSE_URL, ), BuildingSource( "3dbag", "3DBAG LoD2.2", "2", lambda settings, client: ThreeDBagProvider(client), covers=region("netherlands"), auto_priority=100, attribution=ATTRIBUTION, license=LICENSE, license_url=LICENSE_URL, ), BuildingSource( "overture", "Overture Maps", "1", lambda settings, client: OvertureBuildingProvider(settings), attribution=OVERTURE_ATTRIBUTION, license=ODBL, license_url=ODBL_URL, ), BuildingSource( "osm", "OpenStreetMap", "1", OsmBuildingSource, attribution=OSM_ATTRIBUTION, license=ODBL, license_url=OSM_LICENSE_URL, ), ) ) registry.load_installed() return registry
[docs] def resolve_building_source( requested: str, latitude: float, longitude: float, settings: Settings, registry: BuildingSourceRegistry, ) -> dict[str, object]: """Resolve before cache lookup; explicit selections never fall back silently.""" return resolve_source( registry, requested, latitude, longitude, settings, allowed=settings.automatic_building_sources, fallback="global", reserved={"global": GLOBAL_IMPLEMENTATION_VERSION, "none": "1"}, )