Skip to content

feat: your scene can say where on the earth it is (p7-s5) (#324) - #483

Merged
JArmandoAnaya merged 7 commits into
mainfrom
feat/324-p7-s5-world-georeference
Jul 28, 2026
Merged

JArmandoAnaya merged 7 commits into
mainfrom
feat/324-p7-s5-world-georeference

Conversation

@JArmandoAnaya

Copy link
Copy Markdown
Contributor

Closes #324.

p7-s5 — the second sprint of P7, and the one the GIS/lidar/OSM imports need
before they can reproject into anything.

What was missing

Georeferencing was completely greenfield, and <header> leaked data both ways:

Before
Writer synthesized a fresh <header> with four attributes. No children at all.
Reader parse_header read revMajor/revMinor and walked no children, with no diagnostic for anything it dropped — warn_unsupported_root_children explicitly excludes header, so there was no header equivalent of the root sweep.
Repo zero occurrences of geoReference / CRS / WKT / proj-string / EPSG anywhere, and not one committed .xodr carrying a <geoReference>.

So a georeferenced foreign file lost its projection string silently. #453
(fmt-f1) calls that "the most consequential item" on its list and defers the
decision to whoever models §8.5 — this PR, which is why it builds the whole
header-child dispatch and discharges #453's <header> row.

The decision worth reviewing: no PROJ

The issue said "PROJ enters as the reprojection dependency here." It is
deferred to #242 instead (maintainer decision at planning), because PROJ
drags in SQLite3 and a ~9 MB proj.db that must be found at runtime, into a
kernel that builds from CMake alone and ships zero runtime data — to serve no
caller. Nothing in #324's acceptance needs a datum transform.

Instead the sprint authors the construction §8.5 itself recommends:

Alternatively define a custom projection using Transverse Mercator (TM).

tmerc_projection(lat, lon) emits a TM centred on the scene's own origin with
+k=1 +x_0=0 +y_0=0, so the local OpenDRIVE coordinates are the projected
coordinates
and nothing is ever transformed. A CRS RoadMaker did not author is
carried verbatim and reported as opaque — tmerc_origin answers only for that
family, because guessing at a UTM zone's origin would be wrong by its 500 km
false easting. PROJ lands at #242 with a consumer that actually needs it.

What shipped

Layer 0 — GeoReference/GeoOffset on RoadNetwork beside terrain_
(same document-scoped, non-arena shape; default = absent = today's behaviour,
byte for byte). The reader models <geoReference>/<offset> and preserves
every other header child and unknown attribute verbatim. The writer emits the
projection as the only CDATA node RoadMaker produces anywhere, the offset
only when it is not the identity, and derives north/south/east/west
from the network being written — never carried over from the input, which would
become a lie on the first edit. Two ASAM rule ids
(header.proj.max_one_proj, header.offset.centered_coords) and one vendor
rule (header.georeference_mismatch).

Layer 2 — a workspace block in <scene>.rmscene.json holding the box
and the projection string it was framed in. A box framed under a georeference
the scene no longer carries is discarded with a diagnostic, per ADR-0008's
stale-sidecar rule. It carries its own double-width number formatter: the
camera's float path would lose a decimetre at UTM scale.

Editor — Edit ▸ World Georeference… (a non-modal tool window, following
ExportPreviewWindow; the editor still has zero QDialog subclasses),
View ▸ Centre on World Origin, and the export preview's <header> read-out.

Kernel/Python — edit::set_georeference with an empty DirtySet: a
georeference says how coordinates relate to the earth, not where anything is.
Bindings + python/examples/world_georeference.py.

Two things worth knowing

  • The preview reads the header out of the emitted bytes, not the model —
    and that earns its keep immediately: the network can hold an identity offset
    the file will not carry, and only the bytes know. There is a test for exactly
    that case.
  • The vacuity trap. No committed .xodr carried a <geoReference>, so
    every assertion here would have passed forever on a build that dropped the
    element. Fixed with a georeferenced sample plus three corpus seeds, and
    CommittedFixtures.* asserts against them.

Sabotage matrix

Each neutered in turn, rebuilt, re-run — build exit code checked every time,
because two of these first failed to compile and would otherwise have "passed"
on a stale binary.

Sabotage Failed
CDATA emission → plain text HeaderWriter.TheProjectionStringIsWrittenAsCdata only
preserved header children not re-emitted HeaderRoundTrip.TheGeoreferenceAndTheHeaderRemaindersAreAFixedPoint only
max_one_proj guard never latches HeaderGeoReference.ASecondDefinitionIsRefusedByRule only
bounding box never emitted HeaderWriter.TheBoundingBoxDescribesTheNetworkBeingWritten only
owned-attribute filter narrowed both Header.* tests + 162 existing round-trip tests
CRS-mismatch rule disabled WorkspaceMismatch.AWorkspaceFramedInAnotherGeoreferenceIsDiscarded only
workspace through the float formatter SceneSidecarWorkspace.RoundTripsAtFullDoublePrecision only

Two attempts (if (false) on the guard, deleting the to_json_double call)
failed to build under -Werror and were redone as runtime changes — a
sabotage that does not compile leaves a stale binary reporting green.

Verified

  • ctest --preset ci-macos: 2526/2526.
  • pytest python/tests: 358 passed, 1 skipped.
  • git ls-files '*.cpp' '*.hpp' | xargs clang-format --dry-run --Werror: clean.
  • python/examples/world_georeference.py runs end to end.

Known limits, stated

  • No CRS↔CRS transform. A foreign projection is carried, not read (p7-s2: GIS vector/raster import (GDAL/PROJ) #242).
  • The workspace box is not undoable and does not dirty the document — framing
    is not an edit, the same rule the camera pose follows.
  • GW-2 gains steps 25–27 and two pass criteria; the hand-run stays the
    maintainer's gate.

The <header><geoReference> and <header><offset> elements of OpenDRIVE 8.5,
as a document-scoped value on RoadNetwork beside the height field, plus the
verbatim passthrough for the rest of <header>.

No PROJ. The one construction this module understands is the Transverse
Mercator centred on the scene origin that 8.5 itself recommends, in which
local and projected coordinates are the same numbers, so nothing needs
transforming. Any other CRS is carried verbatim and reported as opaque
until p7-s2 brings in the library that can read it.
parse_header becomes the header-child dispatch that #324 and #453 share:
<geoReference> and <offset> are modeled, and everything else the header
holds — <license>, <dataQuality>, <include>, foreign <userData>, unknown
attributes — is preserved verbatim instead of vanishing. A georeferenced
foreign file used to lose its projection string with no diagnostic
anywhere.

The writer emits the north/south/east/west bounding box from the network
it is writing, the projection string as the only CDATA node RoadMaker
produces, and the offset only when it is not the identity.

validate_network gains 8.5's centred-coordinates advisory.
#324)

edit::set_georeference captures the whole value before and after, like the
height field it sits beside. Its DirtySet is EMPTY on purpose: a
georeference says how the scene's coordinates relate to the earth, not
where anything is, so nothing needs re-meshing.

Python gets GeoReference, GeoOffset, the 8.5 offset affine both ways, and
the two Transverse Mercator helpers, plus an example that georeferences a
scene, saves it, and reads the origin back out of the file.
XodrPreview gains the header the writer would produce, read out of the
emitted bytes like every other number there. That distinction earns its
keep immediately: the network can hold an identity offset the file will
not carry, and only the bytes know.

The window names the world origin when it can compute one, and reports
the projection verbatim when it cannot.
…against (p7-s5, #324)

Edit > World Georeference authors the projection two ways — a world
origin that generates the Transverse Mercator 8.5 recommends, or a CRS
pasted verbatim — plus the dataset offset, committed as ONE undoable
command.

The workspace box is the other half and lives in the other layer: it goes
in the scene sidecar with the projection string it was framed in, and a
box framed under a georeference the scene no longer carries is discarded
with a diagnostic rather than framing the user on coordinates that now
mean somewhere else.

View > Centre on World Origin moves the pivot without touching the zoom.
…docs (#324)

Also georeferences a committed sample and adds three corpus seeds. Until
now NOT ONE committed .xodr carried a <geoReference>, so every assertion
about the element would have passed on a build that dropped it — the same
shape as the omission #390 records.

GW-2 gains steps 25-27 and two pass criteria: the world origin must come
back from the file with the digits the user typed, and a workspace framed
in one georeference must not be reused under another.
…324)

The esmini smoke gate caught it on the committed sample: esmini v3.5.0
rejects the token outright — "Unsupported geo reference attr: +no_defs" —
so every scene a user georeferenced would have carried something a major
consumer refuses.

8.5's own example includes +no_defs, but the example is an illustration,
not a rule about what a writer must emit, and the flag is a PROJ.4-era
instruction not to read proj_def.dat — a file removed in PROJ 6. Dropping
it costs nothing and buys back the consumer.

The regression test holds both the generator and the committed samples to
it: the generator assertion alone would not have caught the hand-written
string in the sample.
@JArmandoAnaya

Copy link
Copy Markdown
Contributor Author

The esmini gate earned its keep

First push was 14/15 — esmini round-trip smoke failed, and it was a real
defect in the string RoadMaker generates by default, not a flake:

FAIL assets/samples/straight_road.xodr: esmini could not load it
[error] Unsupported geo reference attr: +no_defs

esmini v3.5.0 rejects +no_defs outright. §8.5's own example carries it,
which is where I took it from — but the example is an illustration, not a rule
about what a writer must emit, and +no_defs is a PROJ.4-era instruction not
to consult proj_def.dat, a file removed in PROJ 6. Every PROJ this
project could target accepts it and ignores it. So it bought nothing and cost a
major consumer, on every scene a user would ever georeference.

Fixed in f76d63d: the generator drops it, and the committed sample with it.

The regression test holds BOTH, deliberately — the generator assertion alone
would not have caught the hand-written string in the sample, and the sample is
what the esmini job actually loads:

TEST(TmercProjection, CarriesNoTokenAKnownConsumerRefuses)

Sabotage-verified: putting +no_defs back fails that test and nothing else.

Worth noting for #242 — this is the kind of thing only a real consumer finds,
and it argues for keeping the esmini gate pointed at anything we generate
rather than only at what we parse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

p7-s5: world georeference settings + reprojection frame

1 participant