1.0.0 • Published 5 years ago

turf-diameter v1.0.0

Weekly downloads
2
License
MIT
Repository
-
Last release
5 years ago

turf-diameter

An unofficial Turf module for calculating the polygon diameter of a Feature or FeatureCollection.

API

Table of Contents

dtheta

Returns the counter-clockwise angle between { coords[a], coords[a + 1] } to { coords[b], coords[b + 1] }

Parameters

Returns Number counter-clockwise angle between 0 and 2 * pi

diameter

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

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