geokit

CI Gitleaks Trivy OSV-Scanner Hex Hex Docs Hex Downloads License OpenSSF Scorecard

Distance, bearing, geohash, polyline, GeoJSON, map tiles and polygon operations for Gleam, on the Erlang and JavaScript targets.

gleam add geokit

Usage

Distance and bearing between two points:

import geokit

pub fn tokyo_to_osaka() -> #(Float, Float) {
  let assert Ok(tokyo) = geokit.lat_lng(latitude: 35.6812, longitude: 139.7671)
  let assert Ok(osaka) = geokit.lat_lng(latitude: 34.6937, longitude: 135.5023)
  #(
    geokit.distance(from: tokyo, to: osaka),
    geokit.initial_bearing(from: tokyo, to: osaka),
  )
  // -> #(402_784.74, 255.42), in meters and degrees
}

Reading GeoJSON with gleam_json and testing a point against it:

import geokit
import geokit/geojson
import gleam/json

pub fn inside_park(input: String) -> Result(geokit.Location, Nil) {
  let assert Ok(park) = json.parse(input, geojson.geometry_decoder())
  let bench = geokit.wrap_lat_lng(latitude: 2.0, longitude: 2.0)
  geokit.locate(bench, in: park)
  // -> Ok(geokit.Inside) for a polygon around (0, 0) to (10, 10)
}

Geohash, encoded polyline and Web Mercator tile:

import geokit
import geokit/geohash
import geokit/polyline
import geokit/tile

pub fn encodings() -> #(String, String, String) {
  let assert Ok(tokyo) = geokit.lat_lng(latitude: 35.6812, longitude: 139.7671)
  let assert Ok(osaka) = geokit.lat_lng(latitude: 34.6937, longitude: 135.5023)
  let assert Ok(hash) = geohash.encode(tokyo, precision: 8)
  let assert Ok(route) = polyline.encode([tokyo, osaka], precision: 5)
  let assert Ok(tokyo_tile) = tile.from_lat_lng(tokyo, zoom: 5)
  #(hash, route, tile.to_quadkey(tokyo_tile))
  // -> #("xn76urx6", "o~wxEkgatYzz_E~}_Y", "13300")
}

The API reference is on HexDocs.

Notes

How the package is tested is described in doc/testing.md.

Verifying releases

Each GitHub Release attaches the Hex package tarball (geokit-<version>.tar), checksums.txt, a cosign signature bundle (checksums.txt.sigstore.json) and build provenance (geokit-<version>.intoto.jsonl). Download the assets, then:

gh attestation verify geokit-<version>.tar --repo nao1215/geokit

cosign verify-blob \
  --bundle checksums.txt.sigstore.json \
  --certificate-identity-regexp '^https://github\.com/nao1215/geokit/\.github/workflows/release\.yml@refs/tags/v' \
  --certificate-oidc-issuer https://token.actions.githubusercontent.com \
  checksums.txt
sha256sum --check checksums.txt

License

MIT