I´m a absolute beginner in QGIS and Qfield. Now at a starting point of a project I´m missing the expression for magnetic declination. So there is a plugin like “compass routes”. It offers a function like to_magnetic to get the magnetic north bearing. In further searching I create a function in QGIS with calculation lat/lon with NOAA Url. It returns me the magnetic declination. But: it won´t work in Qfield, because Qfield won´t support functions. Is it possible to find another way to call the magnetic declination value?
here is the script from Comrade Che (https://gis.stackexchange.com/questions/486836/qgis-how-to-construct-a-declination-diagram/486845#486845)
import requests
import datetime
import pprint
def getDeclination(lat, lon, date=datetime.datetime.now(), model=‘WMM’, result_format=‘json’,
base_url=r’https://www.ngdc.noaa.gov/geomag-web/calculators/calculateDeclination’, key=‘INSETR_YOUR_KEY_HERE’):
“”"
For more info see Help: Magnetic Declination Calculator | NCEI
:param lat: decimal degrees or degrees minutes seconds: -90.0 to 90.0
:param lon: decimal degrees or degrees minutes seconds: -180.0 to 180.0
:param date: Date in datetime.datetime() format
:param model: which magnetic reference model to use: 'WMM' or 'IGRF'
For 'EMM' use base url: https://emmcalc.geomag.info/ with paramater magneticComponent=d
:param result_format: format of calculation results: 'html', 'csv', 'xml', 'json'
:param base_url:
:param key: API access key. Get it here: https://www.ngdc.noaa.gov/geomag/CalcSurvey.shtml
:return:
"""
args = [f'lat1={lat}',
f'lon1={lon}',
f'model={model}',
f'startYear={date.year}',
f'startMonth={date.month}',
f'startDay={date.day}',
f'resultFormat={result_format}',
f'key={key}']
request_url = base_url + '?' + '&'.join(args)
r = requests.get(request_url)
if r.status_code == 200:
return r.json()[0]["result"]["declination"]
else:
r.raise_for_status()
I call it with a line layer (geopackage) with eg. getDeclination(48,41).
Perhaps this can be done with an expression? Or I don´t know, but trigger oder javascript? I think, Qfield will understand trigger. What´s that? Found PostGreSQL Trigger???
Imported from GitHub discussion by @Sickculture on 2024-10-22T15:55:25Z