feat: calculate magnetic info BM-1635#178
Conversation
Changes SummaryTotal Features Changed: 0 Kart DiffKart Diff (0 features)Git DiffGit Diff (1 lines) |
| from qgis.core import QgsExpression, QgsExpressionContext, QgsExpressionContextScope, QgsPoint | ||
|
|
||
| MODEL_NAME = "igrf13" | ||
| MODEL_PATH = "/usr/qgis/models" |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
> 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?
There was a problem hiding this comment.
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.
| conv = source_crs.factors(center_transformed_point).meridianConvergence() | ||
|
|
||
| # magnetic declination | ||
| date = datetime.now() |
There was a problem hiding this comment.
set time from metadata for reproducible outputs?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
|
|
||
| from qgis.core import QgsExpression, QgsExpressionContext, QgsExpressionContextScope, QgsPoint | ||
|
|
||
| MODEL_NAME = "igrf13" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
This does not work for values -0.75 .. -0.25 (round to -0.5 and show as 0½; should be -½).
Values 0.25 to 0.75 should probably show as ½ not 0½
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.tsUpdated the QGIS flatpak container to
build-38as we require the GeographicLib module.DockerfileUpdated the QGIS flatpak container to
build-38as we require the GeographicLib module.qgis/
assets/models/
igrf13.wmm&igrf13.wmm.cofAdded as they are required for the
magnetic_declinationQGIS expression.src/
utils/
mag_dec.pyDefined a new function to prepare and evaluate a
magnetic_declinationQGIS expression.mag_info.pyDefined 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.pyExtended 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.