1.2.2 • Published 2 years ago

polygons-generator v1.2.2

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Polygons Generator

Generate polygons around a point

Options

NameDescriptionValuesdefault value
formatResults formatPolygonFormat.Raw PolygonFormat.GeoJSON PolygonFormat.WKT PolygonFormat.PathPolygonFormat.Raw
customFormatterCustom formatter to apply on the results(points: number) => unknownundefined
randomizeWhether to randomize the polygon vertices or nottrue / falsetrue

Example:

import { PolygonGenerator, PolygonFormat } from "polygons-generator";

const polygonGenerator = new PolygonGenerator({
  format: PolygonFormat.GeoJSON,
});

const lat = 51.46298;
const lon = -0.05939;
const radiusKm = 1;
const numberOfPoints = 10;
const res = polygonGenerator.generate(lat, lon, radiusKm, numberOfPoints);
console.log(JSON.stringify(res, null, 2));

results:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [-0.05262582204837067, 51.46361446514383],
            [-0.05545527484885695, 51.46461461501399],
            [-0.05877349695285488, 51.46797260927282],
            [-0.05940549309865073, 51.4667380406854],
            [-0.06409748585040818, 51.46627080805481],
            [-0.0652177966687324, 51.46276466165517],
            [-0.0630963845499686, 51.46269332060158],
            [-0.0599052372618077, 51.45797059453484],
            [-0.05788872733709241, 51.45911203447885],
            [-0.05491537823336, 51.46082030439293],
            [-0.05262582204837067, 51.46361446514383]
          ]
        ]
      }
    }
  ]
}