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

UTM inverse (WGS84)

The point at a UTM position on WGS84, in 1e-7 degrees. zone must be 1 … 60; easting 0 … 1,000,000,000 mm; northing 0 … 9,400,000,000 mm when north, 1,000,000,000 … 10,000,000,000 mm when south; else an error. n, A as in geo-utm-forward (n = f ÷ (2 − f), A = a ÷ (1 + n) × (1 + n × n ÷ 4 + n × n × n × n ÷ 64), a = 6,378,137, f = 1 ÷ 298.257223563); β1 = n ÷ 2 − 2 × n × n ÷ 3 + 37 × n × n × n ÷ 96, β2 = n × n ÷ 48 + n × n × n ÷ 15, β3 = 17 × n × n × n ÷ 480; δ1 = 2 × n − 2 × n × n ÷ 3 − 2 × n × n × n, δ2 = 7 × n × n ÷ 3 − 8 × n × n × n ÷ 5, δ3 = 56 × n × n × n ÷ 15. With k = 0.9996 × A: ξ = (northing ÷ 1000 − N0) ÷ k (N0 = 0 north, 10,000,000 south), η = (easting ÷ 1000 − 500,000) ÷ k. ξ′ = ξ and η′ = η; for j = 1, 2, 3 in order: ξ′ = ξ′ − βj × sin(2j × ξ) × cosh(2j × η), η′ = η′ − βj × cos(2j × ξ) × sinh(2j × η). χ = asin(sin ξ′ ÷ cosh η′); φ = χ, then for j = 1, 2, 3: φ = φ + δj × sin(2j × χ). lat = deg(φ); lon = (zone × 6 − 183) + deg(atan(sinh η′ ÷ cos ξ′)). The result is round(× 1e7) of each, half away from zero; a lon of 1,800,000,000 or more has 3,600,000,000 subtracted, below −1,800,000,000 added. 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-inverse --lang rust
cd geo-utm-inverse && 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-inverse.wit
package root:component;

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

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

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

    inverse: func(at: utm) -> result<point-e7, string>;
  }
}
Test vectors17›
geo-utm-inverse.cases.json
[
  {
    "args": {
      "at": {
        "zone": 52,
        "north": true,
        "easting": 323394296,
        "northing": 4161554240
      }
    }
  },
  {
    "args": {
      "at": {
        "zone": 30,
        "north": true,
        "easting": 699316181,
        "northing": 5710164327
      }
    }
  },
  {
    "args": {
      "at": {
        "zone": 56,
        "north": false,
        "easting": 334368634,
        "northing": 6250948345
      }
    }
  },
  {
    "args": {
      "at": {
        "zone": 31,
        "north": true,
        "easting": 166021443,
        "northing": 0
      }
    }
  },
  {
    "args": {
      "at": {
        "zone": 32,
        "north": true,
        "easting": 500000000,
        "northing": 6651411190
      }
    }
  },
  {
    "args": {
      "at": {
        "zone": 33,
        "north": true,
        "easting": 512000000,
        "northing": 8683000000
      }
    }
  },
  {
    "args": {
      "at": {
        "zone": 1,
        "north": false,
        "easting": 500000000,
        "northing": 1000000000
      }
    }
  },
  {
    "args": {
      "at": {
        "zone": 60,
        "north": true,
        "easting": 999999999,
        "northing": 9400000000
      }
    }
  },
  {
    "args": {
      "at": {
        "zone": 18,
        "north": true,
        "easting": 583959372,
        "northing": 4507350099
      }
    }
  },
  {
    "args": {
      "at": {
        "zone": 30,
        "north": true,
        "easting": 0,
        "northing": 0
      }
    }
  },
  {
    "args": {
      "at": {
        "zone": 0,
        "north": true,
        "easting": 500000000,
        "northing": 0
      }
    }
  },
  {
    "args": {
      "at": {
        "zone": 61,
        "north": true,
        "easting": 500000000,
        "northing": 0
      }
    }
  },
  {
    "args": {
      "at": {
        "zone": 31,
        "north": true,
        "easting": -1,
        "northing": 0
      }
    }
  },
  {
    "args": {
      "at": {
        "zone": 31,
        "north": true,
        "easting": 1000000001,
        "northing": 0
      }
    }
  },
  {
    "args": {
      "at": {
        "zone": 31,
        "north": true,
        "easting": 500000000,
        "northing": 9400000001
      }
    }
  },
  {
    "args": {
      "at": {
        "zone": 31,
        "north": false,
        "easting": 500000000,
        "northing": 999999999
      }
    }
  },
  {
    "args": {
      "at": {
        "zone": 31,
        "north": false,
        "easting": 500000000,
        "northing": 10000000001
      }
    }
  }
]
Verification6›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 17 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%.