Repository navigation
Linear landmarks on SRTM terrain: roads, railways, bridges, water and airfields without waves and steps #13
Mission-analyzer
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Anyone who has laid OpenStreetMap data over SRTM terrain and satellite imagery knows the result: the highway rolls in waves, the rails jump up and down by half a metre, the river flows downhill and then uphill, a lake gets a step where two terrain chunks meet, a bridge either hangs in the air or runs into the bank, and the drawn road lies next to the real one in the imagery. For a simulator with a camera this is not cosmetic: the pilot navigates by these lines, and the operator matches them against the imagery.
Below is how Mission Analyzer solves it. Two main ideas:
Where the waves and offsets come from
SRTM is a radar model of the surface with ~30 m spacing, not a model of the ground. It sees tree belts along the highway, roofs of roadside houses, hangars and parked aircraft on an airfield, embankments and noise over water. A 3–8 m bump over a hundred metres is normal for SRTM and impossible for a real main line: railway grades are measured in per mille, road grades in percent, and embankments and cuttings take up everything else.
The second problem is chunking. The simulator builds the ground in layers (chunks), and if the water or runway level is computed inside each chunk separately, heights don't match at chunk borders.
The third is offset. OSM mappers trace roads over different imagery (Bing, Esri, Maxar of different years), while the camera uses yet another provider. Imagery from different providers is offset by metres, in places by tens of metres: the Kyiv–Boryspil highway in OSM lies about 30 m away from itself in the imagery. Without a correction, asphalt is painted over the forest next to the real road.
Alignment with the imagery
It is computed on the Map tab when an area is prepared. The area is split into blocks of 4×4 zoom-16 tiles (~1.5×1.5 km, ~1.5 m per pixel). Imagery is downloaded only for blocks containing main roads, railways or an airfield. In each block the line offset is searched within ±40 m in two ways, and the more confident result wins:
An offset is accepted only if the best match is at least 1.25 times above the average: no shift is better than a random one.
A subtlety: straight roads. Along a straight highway every shift matches equally well, so the peak along it is random: in a test, the highway "slid" 40 m along itself. So if all lines in a block run in one direction, the program looks at the match along them. If it is a flat plateau, only the across-line shift is taken. If there is a clear peak (an apron, a runway end, a junction), the full shift is taken.
Between blocks the shift changes smoothly (bilinear, weighted by confidence). A block without its own estimate takes the nearest confident neighbour within ~3 km. The result is an alignment file next to the OSM cache, separate for each imagery provider. Loaders shift all OSM geometry on load: roads, railways, water, airfields, power lines and bridges. The downloaded OSM cache is not modified.
The common technique: a longitudinal profile
Applying it to the ground grid:
The nearest profile point is found not by looping over points but in batches: all grid points in one hash-grid cell are compared with the candidates from the neighbouring 3×3 cells in a single numpy operation.
Profiles are computed once, when an area is prepared (the "Ground model" layer on the Map tab), from the already aligned geometry, and saved per 0.25° tile. A profile is computed along the whole line, so neighbouring tiles hold identical values at their seam. In flight the model is only read. If the alignment is recomputed, the area's model becomes stale and is rebuilt. Where there is no model, profiles are computed in flight by the same rules.
Railways
The strictest profile: a main line is nearly level.
Averaging neighbours is essential: without it, each track of a double line got its own profile, and the catenary wire drew a "tick" as it reached the mast of the neighbouring track. Catenary masts and wires take their height from the same profile, so track, masts and wires stay on one line.
Roads
A road is steeper and closer to the terrain than a railway, but SRTM bumps show on it just the same. The difference from rail is a sliding median before smoothing: an average only smears a bump from a 60 m wide tree belt (8 m becomes 2 m spread over 200 m of road), while a 200 m median cuts it off entirely.
Main and tertiary roads are loaded, with all interchange slip roads. Residential streets are not: there are dozens of times more of them, and they make poor landmarks.
*_link)Common to all: 15 m step; median, then average over 200 m; embankment and cutting up to 6 m; flat across half the carriageway width (by class or the width tag) plus a 20 m slope; shared height at joints and junctions within 15 m. Tertiary roads may be steeper: they follow the terrain more closely, and pulling them like a motorway would create needless embankments on hills. At level crossings the railway profile wins, because it is applied after roads.
Bridges
A bridge is separate geometry (a deck), not ground. Roads and tracks flagged as bridges are excluded from the ground landmarks (otherwise asphalt would be painted on the water).
Deck profile:
Three bugs we found that are worth knowing about:
You can fly under a bridge: a hit is counted only within the deck thickness (1.8 m).
Rivers and lakes
If the water level is computed inside each ground chunk (an SRTM percentile under the water in that chunk), rivers come out wavy and lakes get steps. So:
A river gets a longitudinal profile, with rules of its own:
A lake or pond gets one level for the whole outline (the 15th percentile of SRTM under the entire outline), not one per chunk. If a river flows through it, a small water body takes the river's level, while a large one (the Dnipro channel drawn as a polygon) follows the river profile at every point, because it has a slope. In the ground model a lake's level is stored under the key of its outline (first, middle and last point plus the point count) so it can be found again on the next load.
Islands (holes in a multipolygon) are not treated as water.
Airfields: a flat table
SRTM is especially bumpy on an airfield: hangars, terminals, parked aircraft, tree belts around the field. A runway flattened "threshold to threshold" lies level, but 30 m away there is a hump or a pit, and on landing you see it at once. So the whole airfield is flattened, as Ortho4XP and osm2city do: an airfield is a table.
The table goes on after roads and railways. Taxiways and roads crossing the field get their own profiles; if the table went on first, the profiles would bring the bumps back at the field edges. So the table is applied on top: inside the outline it has the last word.
The runway — by its markings in the imagery. The OSM runway line usually sits well, but Overture has no width, and thresholds are often displaced inwards: the line is drawn along the edge of the pavement, while aircraft land from the "piano keys". At Zhuliany the piano keys are 160 m from the western end of the pavement and 90 m from the eastern end. So each runway is fitted to the imagery separately, and not by "grey concrete" (asphalt can be darker than grass, shoulders lighter) but by markings, which are the same all over the world:
The result for Zhuliany: 45 m wide, like the real runway, the axis exactly on the OSM line, the thresholds on the piano keys.
Runways don't take part in block alignment. Wide shoulders and runway edges "pulled" the line like a road: at Zhuliany the block shifted it by 21 m, right onto the edge. Now blocks are aligned by taxiways, aprons and the roads around, and the runway itself is fitted by its markings.
One ground for everyone. The field plane is part of the ground model, computed in advance on the Map tab. The camera draws from it, the impact check uses it, and the program feeds it to SITL (TERRAIN_DATA replies to the autopilot's requests). Before that, the SITL world was flat at the take-off altitude: take off at Zhuliany (~179 m), land at Boryspil (~130 m), and SITL "landed" the aircraft on invisible ground 43 m above the field. Now SITL lands on the same table that is drawn.
False buildings on lines
Some buildings in Overture were detected by a neural network from imagery, and sometimes a truck on a highway or a patch of asphalt is taken for a building. So a building is not drawn if its centre lies on a main or tertiary road, on a railway, in water, on a runway, taxiway or apron (like osm2city: "no buildings in water or on the airfield"). Roads and water are already aligned with the imagery at that point. Implausible heights are filtered too: above 350 m, or taller than ten times the building's side (this catches the "typo monolith", like the well-known case in MSFS 2020).
Order of corrections
Each correction is applied on top of the previous one:
Everything placed on the ground (buildings, masts, bridges) takes its height from the same chain, so nothing floats and nothing sinks. The ground impact check and SITL use the same ground, so the touchdown happens where you see it.
Where the data comes from
All linear landmarks come from Overture Maps (GeoParquet on S3; only the files that intersect the needed tile are opened). Loading them is described in a separate post. Data: © OpenStreetMap contributors, Overture Maps Foundation, ODbL.
Code: the
geodata/package:align.py— imagery alignment;ground_model.py— the ground model in the map;ground_fixes.py— rail, road and water profiles, the airfield, the urban correction;osm_obstacles.py— bridges.Ground building is in
gl_terrain.py. Every rule is covered by a test intests/: a bump on a road gets cut off, a river doesn't flow uphill, a lake straddling two ground chunks has one height, bridge ends rest on the banks, a flyover over a field is no higher than 6 m, the offset of a highway in a forest is found, and the ground model from the map gives the same result as computing it in flight.Questions and your own approaches are welcome in the comments.
(с) Сергей Горбачевский / Serhii Horbachevskyi, s.gorbi@gmail.com
All reactions