From da6296e305d142560ac8284a838c240d3176af7e Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Tue, 24 Sep 2024 14:16:31 +0200 Subject: [PATCH] docs(readme): geojson module examples --- README.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/README.md b/README.md index 376f6b9..8d8cf35 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,45 @@ const { s2 } = require('s2js') ``` +### GeoJSON support + +The supplementary `geojson` module provides convenience functions for working with GeoJSON data in S2: + +```js +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 `geojson.RegionCoverer` class supports all geometry types including multi-geometries: + +```js +import { geojson } from 's2js' + +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.