Skip to content

missinglink/s2js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

b8298c9 · Apr 1, 2025
Aug 12, 2024
Sep 24, 2024
Aug 21, 2024
Aug 19, 2024
Sep 4, 2024
Sep 4, 2024
Apr 1, 2025
Jul 24, 2024
Jul 24, 2024
Jul 18, 2024
Aug 14, 2024
Aug 28, 2024
Sep 24, 2024
Sep 2, 2024
Sep 2, 2024
Jul 18, 2024
Sep 3, 2024

Repository files navigation

s2js

s2js is a Javascript port of the s2 spherical geometry library.

| github | npm | documentation | demo |

Installation

npm install s2js

Usage

The library is available as both ESM & CJS modules:

ESM

import { s2 } from 's2js'

CJS

const { s2 } = require('s2js')

CDN

<script type="module">
  import { s2 } from 'https://esm.sh/s2js'
</script>

GeoJSON support

The supplementary geojson module provides convenience functions for working with GeoJSON data in S2:

import { geojson } from 's2js'

const s2Polyline = geojson.fromGeoJSON({
  type: 'LineString',
  coordinates: [
    [102.0, 0.0],
    [103.0, 1.0],
    [104.0, 0.0],
    [105.0, 1.0]
  ]
})

The RegionCoverer supports all geometry types including multi-geometries:

const coverer = new geojson.RegionCoverer({ maxCells: 30 })

const union = coverer.covering({
  type: 'Polygon',
  coordinates: [
    [
      [100.0, 0.0],
      [101.0, 0.0],
      [101.0, 1.0],
      [100.0, 1.0],
      [100.0, 0.0]
    ]
  ]
})

Contributing

If you'd like to contribute a module please open an Issue to discuss.

Copyright

© 2024 Peter Johnson <github:missinglink>

This source code is published under the Apache-2.0 license.