Skip to content

Store the SRID when creating a database and reject geographic SRIDs - #150

Merged
ryan-kipawa merged 2 commits into
mainfrom
fix/141-create-srid
Oct 5, 2026
Merged

ryan-kipawa merged 2 commits into
mainfrom
fix/141-create-srid

Conversation

@ryan-kipawa

Copy link
Copy Markdown
Collaborator

Fixes #141.

What was wrong

  • db.srid == -1 after create(). CreateModelTables uses its srid argument only to look up a projection string. The SRID it stores, in m_Configuration and geometry_columns, stays at -1. So Database.srid reads -1, and geometry written later is tagged -1. The same happens when only projection_string is given.
  • srid=4326 gives Google Maps - Mercator. When no projection string is passed, MIKE+ replaces a geographic projection with Google Maps - Mercator, without saying so.

MIKE+ GUI comparison

I created a new model through the MIKE+ 2026 U1 GUI (File → New, Coordinate system → Browse). With ETRS89 / UTM zone 32N chosen after Sirius (25832) had been open, the database stored 25832. I then chose ETRS89 / UTM zone 33N, also after Sirius. It stored the 33N projection string but SRID 25832. So the GUI doesn't derive the SRID from the chosen projection either: it carries over the SRID of the project open before. That one is a MIKE+ bug, which I'll report separately. The GUI only offers projected systems (plus Google Maps - Mercator), never geographic ones.

Fix

  • When srid is given, create() looks up its WKT with GetProjectionOGCWKT in a throwaway database before any target file is touched, so overwrite=True still keeps the old file on bad input. Unknown and geographic SRIDs raise ValueError. The WKT is passed to CreateModelTables.
  • When only projection_string is given, the SRID is derived with GetSRIDFromProjStr.
  • After CreateModelTables, the SRID is written to m_Configuration and geometry_columns. A node inserted afterwards is stored with SRID 25832, checked in the geometry blob.
  • The user guide prints srid again, and there's a changelog entry.

Tests

pytest tests/database/test_database.py -k "Create or srid or projection" passes (16 tests) against MIKE+ 2026 U1. New tests:

  • srid=25832 round trip, including a geometry insert;
  • srid derived from projection_string;
  • 4326 and 999999 raise ValueError and keep the existing file under overwrite=True.

just lint and just typecheck pass. just lint-changed reports nothing in database.py; its remaining errors are in files this PR doesn't touch.

🤖 Generated with Claude Code

ryan-kipawa and others added 2 commits October 5, 2026 15:21
CreateModelTables uses its srid argument only to look up a projection
and leaves the stored SRID (m_Configuration and geometry_columns) at -1,
so Database.srid and every geometry written later used -1. create() now
writes the SRID itself, deriving it from projection_string when MIKE+
recognises the projection.

Given a geographic SRID such as 4326, MIKE+ silently stored Google Maps -
Mercator. create() now raises ValueError for geographic or unknown SRIDs,
looked up in a throwaway database so overwrite=True keeps the old file.

Fixes #141

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

📚 Preview this PR's docs locally

Fetch the just-built site and open it in your browser:

# this exact build
great-docs preview --run 37321808323

# or always the latest build for this PR
great-docs preview --pr 150
Auth & tips
  • Requires great-docs: pip install great-docs (or run via pipx/uvx).
  • Auth: run gh auth login then add --use-gh, or set GITHUB_TOKEN (needs Actions: read).
  • Jump to a page: add --path reference/index.html.
  • Latest vs exact: --pr <n> grabs the newest build; --run <id> pins this one.
  • Re-download: --refresh ignores the local cache.

@ryan-kipawa
ryan-kipawa merged commit 6951d48 into main Oct 5, 2026
9 checks passed
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.

Database created with srid has srid == -1 and srid=4326 gives Google Mercator

1 participant