An unofficial Turf function for calculating the polygon diameter of a Feature.
npm install turf-diameterAn unofficial Turf module for calculating the polygon diameter of
a Feature or FeatureCollection.
#### Table of Contents
- dtheta
- Parameters
- diameter
- Parameters
- Examples
Returns the counter-clockwise angle between{ coords[a], coords[a + 1] } to { coords[b], coords[b + 1] }
#### Parameters
- coords Array<\[number, number]> List of GeoJSON coordinates
- a Number starting index of the first ray
- b Number starting index of the second ray
Returns Number counter-clockwise angle between 0 and 2 * pi
Takes a Feature or FeatureCollection and returns the
polygon diameter.
Internally, this uses the rotating calipers method and pseudocode
described here.
The concepts from the article are based off of the following paper:
Shamos, Michael (1978). "Computational Geometry" (PDF). Yale University. pp. 76–81.
The rotating calipers method requires a convex hull so we use mapbox's concaveman,
which runs in O(n * log n) time as stated here.
The algorithm in the paper runs in about O(n) time, making this entire algorithm
run in O(n) + O(n log n) = O(n log n) time.
#### Parameters
- geojson GeoJSON input Feature or FeatureCollection
#### Examples
``javascript
const points = turf.featureCollection([
turf.point([10.195312, 43.755225]),
turf.point([10.404052, 43.8424511]),
turf.point([10.579833, 43.659924]),
turf.point([10.360107, 43.516688]),
turf.point([10.14038, 43.588348]),
turf.point([10.195312, 43.755225])
]);
const len = diameter(points);
``
Returns Number the polygon diameter of the GeoJSON