from qgis.core import * from qgis.gui import * ''' Written by @klaskarlsson Licence LGPL Parameters: -g : Grid North Reference, default 0 -m : Magnetic Declination relative True North, default 0 -t : True North Reference relative Grid North, default 0 -s : SVG size centimeters, default 2.5 ''' import math def generatesvg(g, m, t, s): t = round(t, 1) svg1="\n" svg1+="\n" svg1+="\n" svgm=" \n" svgm+=" \n" svgm+=" Mag Decl. = %s°\n" svgm+=" \n" svgt=" \n" svgt+=" \n" svgt+=" True North = %s°\n" svgt+=" \n" svgg=" \n" svgg+=" GN\n" svgg+=" \n" svgg+=" Grid North = %s°\n" svgg+=" \n" svgr=" \n" svgr+=" \n" svgr+="\n" vg = math.radians(g) vt = math.radians(t) vm = math.radians(t+m) xm = 200 + 300 * math.sin(vm) ym = 380 - 300 * math.cos(vm) axm = 200 + 305 * math.sin(vm) aym = 380 - 305 * math.cos(vm) bxm = 200 + 335 * math.sin(vm) bym = 380 - 335 * math.cos(vm) cxm = 200 + 305 * math.sin(vm + math.radians(2)) cym = 380 - 305 * math.cos(vm + math.radians(2)) generera = svg1 generera += svgm % ( xm, ym, axm, aym, bxm, bym, cxm, cym, m) xt = 200 + 330 * math.sin(vt) yt = 380 - 330 * math.cos(vt) axt = 200 + 330 * math.sin(vt - math.radians(1.8)) ayt = 380 - 330 * math.cos(vt - math.radians(1.8)) bxt = 200 + 360 * math.sin(vt) byt = 380 - 360 * math.cos(vt) cxt = 200 + 330 * math.sin(vt + math.radians(1.8)) cyt = 380 - 330 * math.cos(vt + math.radians(1.8)) dxt = 200 + 349 * math.sin(vt - math.radians(2.6)) dyt = 380 - 349 * math.cos(vt - math.radians(2.6)) ext = 200 + 349 * math.sin(vt + math.radians(2.6)) eyt = 380 - 349 * math.cos(vt + math.radians(2.6)) generera += svgt % ( xt, yt, axt, ayt, bxt, byt, cxt, cyt, dxt, dyt, ext, eyt, t) xg = 200 + 360 * math.sin(vg) yg = 380 - 360 * math.cos(vg) axg = 200 + 363 * math.sin(vg) ayg = 380 - 363 * math.cos(vg) generera += svgg % (xg, yg, axg, ayg, g, g) xrt1 = 200 + 300 * math.sin(vg) yrt1 = 380 - 300 * math.cos(vg) xrt2 = 200 + 300 * math.sin(vt) yrt2 = 380 - 300 * math.cos(vt) xrm1 = 200 + 280 * math.sin(vt) yrm1 = 380 - 280 * math.cos(vt) xrm2 = 200 + 280 * math.sin(vm) yrm2 = 380 - 280 * math.cos(vm) if (vm <= vt): mp = 0 else: mp = 1 if (vt <= vg): tp = 0 else: tp = 1 generera += svgr % (xrt1, yrt1, tp, xrt2, yrt2, xrm1, yrm1, mp, xrm2, yrm2) return generera @qgsfunction(args='auto', group='Military') def north_ref_svg(grid_north, true_north, magnetic_north, size_svg, feature, parent): """

Generate North Reference SVG.

Place inside HTML frame

  • arg 1: Grid North (normally 0)
  • arg 2: True North (calc)
  • arg 3: Magnetic Declination (look up)
  • arg 4: SVG size in centimeters

Example usage:

northref(0, 3.4, -7, 2.5) """ return generatesvg(grid_north, magnetic_north, true_north, size_svg)