Skip to content

feat: calculate magnetic info BM-1635#178

Open
tawera-manaena wants to merge 20 commits into
masterfrom
feat/support-magnetic-declination
Open

feat: calculate magnetic info BM-1635#178
tawera-manaena wants to merge 20 commits into
masterfrom
feat/support-magnetic-declination

Conversation

@tawera-manaena

@tawera-manaena tawera-manaena commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

This piece of work also resolves BM-1634 (Jira).


Motivation

The magnetic declination panel tells map users the difference between grid north and magnetic north for this map sheet, including the rate of change over time. This is critical information for users navigating with a compass. Replicating this in QGIS ensures the panel is dynamically generated from accurate, location-specific data rather than manually authored, reducing the risk of error and the burden on cartographers.

Modifications

  • packages/

    • map/

      • src/

        • python.runner.ts

          Updated the QGIS flatpak container to build-38 as we require the GeographicLib module.

      • Dockerfile

        Updated the QGIS flatpak container to build-38 as we require the GeographicLib module.

    • qgis/

      • assets/models/

        • igrf13.wmm & igrf13.wmm.cof

          Added as they are required for the magnetic_declination QGIS expression.

      • src/

        • utils/

          • mag_dec.py

            Defined a new function to prepare and evaluate a magnetic_declination QGIS expression.

          • mag_info.py

            Defined two key functions: one to calculate the magnetic information for a given sheet, and one to convert magnetic information values into ready-to-display strings.

        • qgis_export.py

          Extended the existing logic to call the magnetic information functions and inject the resulting values into the project as layout variable key-value pairs.

Verification

When we look at the visual snapshot images, we can see that the system is successfully injecting layout variable values into the magnetic information component.

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown

Changes Summary

Total Features Changed: 0
Datasets Affected: 0
Git Diff Lines: 1

Kart Diff

Kart Diff (0 features)

Git Diff

Git Diff (1 lines)

@tawera-manaena tawera-manaena changed the title test: strategy for injecting layout variables feat: calculate magnetic info BM-1635 Jun 7, 2026
@tawera-manaena tawera-manaena marked this pull request as ready for review June 11, 2026 21:54
@tawera-manaena tawera-manaena requested a review from a team as a code owner June 11, 2026 21:54
Comment thread packages/qgis/src/utils/mag_dec.py Outdated
from qgis.core import QgsExpression, QgsExpressionContext, QgsExpressionContextScope, QgsPoint

MODEL_NAME = "igrf13"
MODEL_PATH = "/usr/qgis/models"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The map/Dockerfile copies this package to /app/qgis and not /usr/qgis.
Does that mean that the models folder in this package is not needed or should this path be /app/qgis/models ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

> docker run -it --rm --entrypoint /bin/bash map

root@e814bea4184e:/# ls app/qgis/models/
igrf13.wmm  igrf13.wmm.cof

root@e814bea4184e:/# ls usr/qgis/models/
igrf13.wmm  igrf13.wmm.cof

The model files exist in both locations. Do you think this is unintended?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if they're provided by the container (in /usr/qgis) then why do we need to provide them here?
If we want to provide them here, then why not use them in the container as well?

I don't have a strong opinion on which way to take, but feel like a combination of both (as is now) can easily lead to unintended outcomes.

Comment thread packages/qgis/src/utils/mag_info.py Outdated
conv = source_crs.factors(center_transformed_point).meridianConvergence()

# magnetic declination
date = datetime.now()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

set time from metadata for reproducible outputs?

@tawera-manaena tawera-manaena Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We certainly want to support custom dates. However, I want to avoid deeply passing props, if possible. Did you have a strategy in mind? Metadata?

@schmidtnz schmidtnz Jun 14, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sorry, I have no specific strategy in mind.

The challenge will be to align what qgis does locally vs headless map production.

For production, this might be able to come from STAC if we can find an appropriate place for it? I don't think py currently reads the STAC so might be too big a change. (STAC was my initial thought, what I referred to as "metadata" above)

Maybe we can add an additional qgis project variable? It will need to be updated manually or recalculated based on a set rule?

Comment thread packages/qgis/src/utils/mag_dec.py Outdated

from qgis.core import QgsExpression, QgsExpressionContext, QgsExpressionContextScope, QgsPoint

MODEL_NAME = "igrf13"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we have an upgrade plan for when/how new models get introduced?
I.e. should this always be kept up to date (through configuration) with the latest igrf model, or should version 13 stay pinned?

@tawera-manaena tawera-manaena Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

IGRF models are released every five years, the latest being IGRF-14 in 2025. That said, I cannot find the two required files anywhere online.

QGIS requires both the .wmm and .wmm.cof files. So, it seems we're stuck with IGRF-13 in the meantime.

Upgrade plan? No idea. Different IGRF versions can render different values for the same date. Newer versions being more accurate if the given date is within the speculative range of the older version.


if gm_degrees_rounded.is_integer():
gm_degrees_str = f"{int(gm_degrees_rounded)}"
else:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This does not work for values -0.75 .. -0.25 (round to -0.5 and show as ; should be ).
Values 0.25 to 0.75 should probably show as ½ not

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