Circle To Polygon
The GeoJSON spec does not support circles. If you wish to create an area that represents a circle, your best bet is to create a polygon that roughly approximates the circle. In the limit of the number of edges becoming infinite, your Polygon will match a circle.
Installation
npm install --save circle-to-polygon
or
yarn add circle-to-polygon
Usage
Example
const circleToPolygon = require("circle-to-polygon");
const coordinates = [-27.4575887, -58.99029];
const radius = 100;
const numberOfEdges = 32;
let polygon = circleToPolygon(coordinates, radius, numberOfEdges);
Parameters
coordinates
Array of length 2 or 3 *required
- First Element:
longitude
Number *required, can be any number <=180
and >=-180
- Second Element:
latitude
Number *required, can be any number <=90
and >=-90
- Third Element: Ignored if present
radius
Number *required, can be any number >0
numberOfEdges
Number can be any number >=3
, defaults to 32 when undefinedearthRadius
Number can be any number >0
, defaults to 6378137 (equatorial Earth radius) when undefinedbearing
Number can be any number, defaults to 0 when undefined
Disclaimers
- Decimal values will not throw error for numberOfEdges! Instead one of the edges of the polygon will be smaller than the others. In other words, all edges will not have the same length if a decimal number is passed as numberOfEdges.
- A circle whoes edge cross longitude edges (-180 or 180) or a latitude edge (-90 or 90) will contain coordinate points that are outside the stanardized coordinates (eg: [182, 23]). This is because there are two ways to represent a line going from [179, x] to [181, y]. One way is simply writing it as [[179, x], [182, y]] while the other is to write it as a multi-polygon. Version <= 2.0.x does only support the first way while release of 2.1.0 will support multi-polygons as well.
Authors
- Gabriel Zimmermann
- Johannes Jarbratt
Contributors
License
ISC