Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
geo / geo-utm-forwardOpenRuns on Liberas

UTM forward (WGS84)

The UTM zone, hemisphere (north = lat ≥ 0, so −0 is north), easting and northing in millimetres of point at on WGS84 (a = 6,378,137, f = 1 ÷ 298.257223563). lat must be in −80 … 84, else an error. zone = floor((lon + 180) ÷ 6) + 1, or 60 when lon = 180; then the exceptions: Norway (56 ≤ lat < 64 and 3 ≤ lon < 12) is zone 32; Svalbard (72 ≤ lat ≤ 84 and 0 ≤ lon < 42) is zone 31 when lon < 9, 33 when lon < 21, 35 when lon < 33, else 37. λ0 = zone × 6 − 183. Krüger's series to n³: n = f ÷ (2 − f); A = a ÷ (1 + n) × (1 + n × n ÷ 4 + n × n × n × n ÷ 64); α1 = n ÷ 2 − 2 × n × n ÷ 3 + 5 × n × n × n ÷ 16, α2 = 13 × n × n ÷ 48 − 3 × n × n × n ÷ 5, α3 = 61 × n × n × n ÷ 240; c = 2 × √n ÷ (1 + n). φ = rad(lat), λ = rad(lon − λ0); t = sinh(atanh(sin φ) − c × atanh(c × sin φ)); ξ = atan(t ÷ cos λ); η = atanh(sin λ ÷ √(1 + t × t)). E = η and N = ξ; for j = 1, 2, 3 in order: E = E + αj × cos(2j × ξ) × sinh(2j × η), N = N + αj × sin(2j × ξ) × cosh(2j × η). easting = 500,000 + 0.9996 × A × E; northing = N0 + 0.9996 × A × N with N0 = 0 north, 10,000,000 south; the result is round(× 1000) of each, half away from zero. A point is {lat, lon} in degrees; it is an error unless both are finite with −90 ≤ lat ≤ 90 and −180 ≤ lon ≤ 180 (NaN and ±Infinity are errors). rad(v) = v × π ÷ 180 and deg(v) = v × 180 ÷ π, left to right, with π the binary64 nearest π. Arithmetic is IEEE 754 binary64, each operation rounded to nearest-even and evaluated in exactly the order written (left to right; no fused multiply-add). sin, cos, tan, asin, atan, atan2, exp and ln are the platform's own: the result is an integer, round half away from zero, so any libm accurate to a few ulps gives the same answer except within a hair of a rounding boundary.

From your terminal

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init geo-utm-forward --lang rust
cd geo-utm-forward && liberas build && liberas submit

Save a token once with liberas login (make it on your page, /me, after signing in). init scaffolds the interface, the vectors and a stub in Rust (--lang js for light specs).

Interface (WIT)28 lines›
geo-utm-forward.wit
package root:component;

world root {
  import liberas:geo/types@0.1.0;

  export liberas:geo/utm-forward@0.1.0;
}
package liberas:geo@0.1.0 {
  interface types {
    record point {
      lat: f64,
      lon: f64,
    }

    record utm {
      zone: u8,
      north: bool,
      easting: s64,
      northing: s64,
    }
  }
  interface utm-forward {
    use types.{point, utm};

    forward: func(at: point) -> result<utm, string>;
  }
}
Test vectors21›
geo-utm-forward.cases.json
[
  {
    "args": {
      "at": {
        "lat": 37.5665,
        "lon": 126.978
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": 51.5074,
        "lon": -0.1278
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": -33.8688,
        "lon": 151.2093
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": 0,
        "lon": 0
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": -0.0001,
        "lon": 3
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": 60,
        "lon": 5
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": 78.2232,
        "lon": 15.6267
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": 80,
        "lon": 8.9
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": 83.9,
        "lon": 40
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": -79.9,
        "lon": -179.9
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": 84,
        "lon": 180
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": -80,
        "lon": 177
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": 40.7128,
        "lon": -74.006
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": 84.0000001,
        "lon": 0
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": -80.5,
        "lon": 0
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": "NaN",
        "lon": 0
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": 0,
        "lon": "Infinity"
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": 90.0000001,
        "lon": 0
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": -91,
        "lon": 0
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": 0,
        "lon": 180.5
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": 0,
        "lon": "-Infinity"
      }
    }
  }
]
Verification6›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 21 vectors plus ones generated from the interface's types: edge values and random ones seeded by your component's hash.
  • Components may import nothing but specs: no files, no network, no clock.
  • Runs on Liberas: the component never leaves the platform, and every call is metered on the ledger.
  • A remote call may execute up to 1,000,000 instructions.
  • Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.