Skip to content

Road Processors

Fetch and parse OpenStreetMap road geometry, (de)serialize the roads sidecar, and build the terrain-flatten operations that sit roads on well-resolved terrain. For the concept and configuration, see Roads and Buildings & Roads config.

Fetching & parsing

s2gos_generator.processors.roads.fetch_osm_data

fetch_osm_data(
    roads_cfg, bbox_south, bbox_west, bbox_north, bbox_east
) -> Optional[dict]

Fetch or load OSM road data based on config source.

s2gos_generator.processors.roads.parse_roads

parse_roads(
    osm_data: dict,
    roads_cfg,
    coordinate_system,
    scene_bounds,
) -> list[Road]

Parse OSM road ways into Road segments, clipped to scene bounds.

s2gos_generator.processors.roads.Road dataclass

Road(centerline: LineString, width: float, material: str)

A single road segment in scene coordinates.

s2gos_generator.processors.roads.RoadsFetchError

Bases: RuntimeError

Raised when the Overpass API fails on every retry attempt.

Sidecar (de)serialization

s2gos_generator.processors.roads.roads_to_sidecar

roads_to_sidecar(roads: list[Road]) -> dict

Serialize road segments to the roads-sidecar structure.

s2gos_generator.processors.roads.roads_from_sidecar

roads_from_sidecar(data: dict) -> list[Road]

Reconstruct road segments from the roads-sidecar structure.

Returns an empty list for an unrecognised schema version.

Terrain flattening

s2gos_generator.processors.roads.build_road_terraform_operations

build_road_terraform_operations(
    roads: list[Road],
    dem_data,
    *,
    transition_buffer_m: float,
    gradient_threshold: float,
    thin_road_skip_m: float,
) -> list

Build terrain-flatten operations for roads using a DEM gradient filter.

Returns an empty list when there are no road segments or all are filtered out by the gradient threshold.