Skip to content

fix: Norway kmm2 files that already store projected coordinates are not converted again - #16

Open
fippli wants to merge 1 commit into
masterfrom
fix/norway-projected-coordinates
Open

fippli wants to merge 1 commit into
masterfrom
fix/norway-projected-coordinates

Conversation

@fippli

@fippli fippli commented Sep 21, 2026

Copy link
Copy Markdown

Problem

read_kmm2 recognises a Norway ("Banenor") file by NorKmmToKmm in the VER header and converts its coordinate columns from WGS84 degrees to SWEREF99 TM. Newer files carry the same header (NorKmmToKmm2_1.03) but already store projected northing/easting in those columns:

POS  1482600   1400  7     100    ?  …  59.913507          10.636717           (2025 file)
POS  29267400  1420  52.0  812.0  5  …  6632290.739231621  230493.47419632197  (2026 file)

Converting metres as if they were degrees produces garbage. On 20260519_025932_2011T.kmm2, 17 423 of 17 712 rows came out with coordinates nowhere near Scandinavia. Everything built on the library — the deepinspection provider's positions worker, wire's processing job — ingests that silently.

Fix

Decide from the values, since the header cannot tell the two apart: a latitude is at most 90, a Scandinavian northing is in the millions. latlon_to_sweref converts only when the columns hold degrees (is_degrees, on the medians so a malformed row cannot flip it); projected files pass through unchanged.

The projected files are zone 33 ETRS89 (UTM 33N), which shares its projection parameters with SWEREF99 TM, so passing them through is correct to within the datum difference (centimetres). Checked against Bane NOR's official network: read this way, the 2026 file's open-air positions lie a median 0.1 m from the track centre line.

Testing

  • New fixture tests/norway_projected.kmm2: the four positions of the existing tests/norway.kmm2, synthetically re-written in the newer layout (projected coordinates, float kilometre/metre, datetime column). The test asserts both fixtures land on the same northing/easting and recover the same latitude/longitude.
  • uv run pytest: 16 passed. black and flake8 clean on the changed file.
  • Both real files now parse with 100 % plausible coordinates (the 2025 lat/lon file is unchanged in behaviour).

Needs a release (v0.1.11) before the deepinspection positions worker, pinned at kmm>=0.1.10,<0.2, picks it up.

🤖 Generated with Claude Code

…ot converted again

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

@FelixAbrahamsson FelixAbrahamsson left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, the median check is a clever way to handle that ambiguity.

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.

2 participants