#1507

Roads: a segment merged from several OSM ways takes the surface most of it has

OpenTachywants to merge intofrom

Overview

A road segment that Overture merged from several OpenStreetMap ways took the OSM surface of one of them, the way covering most of it, along its whole length. Now it takes the surface that most of the segment has. Each way's surface along the segment comes from Overture's own surface rules, so a gravel track merged with a short grass track stays gravel.

Closes #1506 (the issue explains the bug with the Herrenweg example and how often it happens).

Follows #683 / #689: that fix made src_record the segment's own way, not the route relation. On a segment of several ways that is still one of them.

Open PRs that read roads._map_surface_value (#1156, #1362, #1486) get the corrected value without changes, and none of them touches these lines.

The bug in short

  • Merging: Overture merges the ways between two junctions into one segment and keeps each source way with its range along it (src_ways).
  • Join: osmtags.join joins OSM's tags from one of them (src_record, the longest), and roads._map_surface_value used that way's surface for the whole segment.
  • Result: Sulzburg's Herrenweg is 56 % gravel and 35 % grass track (w50822566, the longest single way). It was drawn as a grass track with grass growing on it.
  • Cell dependence: In the neighbouring cell, whose tag set lacked w50822566, the join fell back to the same-named gravel way. The same road came out as grass in one cell and gravel in the next.

Changes

server/roads.py:

  • osm_surface_column(feats) returns the osm_surface column with the merged segments corrected. It is kept on the layer, and the layer's own column is left unchanged.
    • It replaces the plain column at its three readers: _map_surface_value, _map_surface_values (the spec kernels' input) and sweden_surfaces.
    • A segment with one way, no OSM surface or no surface rules is untouched.
  • merged_surface(cls, osm, own, rules) (pure) weighs each look by its share of the segment:
    • Looks: paved, cobble, gravel or dirt (surface_kind), plus grass and rock (terrain_surface).
    • The joined way's look counts its own ranges.
    • Overture's rules count only their length outside those ranges, so nothing is counted twice.
    • Overture's unknown is no surface and is never counted.
    • Overture's generic unpaved counts as the joined way's look when that look is unpaved too. Overture's list has no grass, ground or compacted; OSM's values are folded into unpaved. So an unpaved says nothing against an OSM grass or compacted. Without this rule, 115 more segments would have changed in the sample below, most of them grass → dirt, which is wrong.
    • Outcome: If another look has the larger share, that look's value covering the most of the segment is taken. A tie keeps OSM's value.
  • Out of scope: One look per segment is still the rule. The segment is not split at the way boundaries: that would change feature ids, connectors and the decisions archives, so I'd keep it for a follow-up if wanted.

Effect

Measured on the 1,261 cached road cells on my disk (Germany, Italy, some US places):

  • 214,856 segments; 27,383 are merged from several ways; 18,272 of those have an OSM surface.
  • 79 segments (29.4 km) change look:
changesegments
paved → cobble22
paved → gravel17
cobble → paved12
gravel → paved10
dirt → paved4
dirt → gravel4
other10

By class: 27 track, 23 footway, 14 path, 7 service, plus a few streets.

Spot checks against the OSM API:

  • Herrenweg: grass → gravel. The gravel ways w50822567 and w1563039711 make up 56 % of the segment.
  • Via di Isola (Italy): asphalt → gravel. w42833804 is asphalt (31 %); w1013447966, w42886967 and w42886968 are pebblestone (69 %).
  • A farm track (w68460852, asphalt, 47 %, with w68461199 and w68461997, gravel, 53 %): asphalt → gravel.

Drivability baseline: casagranda_bridge updated (please review)

The drivability ratchet got worse at one site, Galleria Casagranda, score 39.8 → 41.1. The cause is a correct surface change, so I updated that site's baseline (drivability.py --update casagranda_bridge, no other site touched). Here is the evidence so you can decide:

  • The road: track 56a28a10-… is merged from four ways. Three of them are surface=asphalt in OSM (w1468991492, w228756204, w1468991493: 71 % of the segment). The fourth, w857176117 (29 %), is ground, and it was the joined one.
  • Before / now: before, the whole track was a dirt road; now it is paved.
  • Why it scores worse: a paved road is graded differently. Where it meets the dirt track 053629ed-… at the tunnel, the step grows from 0.21 to 0.45 m (its tunnel end from 0.79 to 0.85 m). The already broken step on the track itself goes from 6.25 to 6.71 m.
  • Reading: the surface is now right. The steps show a weakness in grading where a paved track meets a dirt one, which existed before and is outside this PR.

If you'd rather keep the old baseline and look at the grading first, I'll drop the baseline commit.

Cache

  • No mapdata layer version bump: the correction is made when the roads are read, so cached cells get it without being fetched again.
  • The road plans and tiles are keyed by the code (revisit.code_key), so they rebuild on their own.

Files

  • server/roads.py
  • server/tests/test_roads.py
  • server/tests/fixtures/drivability_baseline.json (casagranda_bridge only)

Validation

  • test_roads.MergedSurfaceTest:
    • The Herrenweg segment with its real six way ranges and Overture rules is gravel, not a grass road. It comes out gravel in both cells, whichever way the join found.
    • A paved street merged with a short gravel stretch keeps OSM's asphalt. OSM's compacted over Overture's unpaved keeps compacted.
    • A tie keeps the joined way's value.
    • A single way, or a segment without an OSM value, is untouched (the column itself is returned).
    • merged_surface: the joined way's range is not counted twice, the unpaved and unknown rules work as described, and the winning look's longest value is taken.
    • The corrected column is kept on the layer, and the layer's own column is unchanged.
  • The full server suite (514 files, each run on its own, Windows 11):
    • 479 files pass.
    • The other 35 fail or error the same way on dev without this change on my machine (missing optional packages such as zstandard, Windows symlink rights, network and real-data fixtures).
    • The exceptions were test_server (a timeout) and test_shared_gate (passed on a re-run) as flukes, plus test_drivability (the baseline above), which now passes.
  • In game (Windows 11, BeamNG.drive 0.40.5): the Herrenweg and the tracks around Laufen and Sulzburg that the fix changes now have the right surface; no more grass on the Herrenweg.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WYV5w24vV3RfW3r9wAopn4