From ec3049e84f14404de6e4f47dbe7825e61d82e082 Mon Sep 17 00:00:00 2001 From: Marc Jansen Date: Sun, 31 Oct 2021 22:52:13 +0100 Subject: [PATCH] More precise documentation of supported units for buffering --- packages/turf-buffer/README.md | 31 ++++++++++++++++++++++--------- packages/turf-buffer/index.js | 13 ++++++++++++- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/packages/turf-buffer/README.md b/packages/turf-buffer/README.md index 450885eb46..7467236db0 100644 --- a/packages/turf-buffer/README.md +++ b/packages/turf-buffer/README.md @@ -4,7 +4,19 @@ ## buffer -Calculates a buffer for input features for a given radius. Units supported are miles, kilometers, and degrees. +Calculates a buffer for input features for a given radius. Units supported are: + +* centimeters or centimetres +* degrees +* feet +* inches +* kilometers or kilometres +* meters, metres +* miles +* millimeters, millimetres +* nauticalmiles +* radians +* yards When using a negative radius, the resulting geometry may be invalid if it's too small compared to the radius magnitude. If the input is a @@ -12,15 +24,16 @@ FeatureCollection, only valid members will be returned in the output FeatureCollection - i.e., the output collection may have fewer members than the input, or even be empty. -**Parameters** +### Parameters -- `geojson` **([FeatureCollection][1] \| [Geometry][2] \| [Feature][3]<any>)** input to be buffered -- `radius` **[number][4]** distance to draw the buffer (negative values are allowed) -- `options` **[Object][5]** Optional parameters (optional, default `{}`) - - `options.units` **[string][6]** any of the options supported by turf units (optional, default `"kilometers"`) - - `options.steps` **[number][4]** number of steps (optional, default `8`) +* `geojson` **([FeatureCollection][1] | [Geometry][2] | [Feature][3]\)** input to be buffered +* `radius` **[number][4]** distance to draw the buffer (negative values are allowed) +* `options` **[Object][5]** Optional parameters (optional, default `{}`) -**Examples** + * `options.units` **[string][6]** any of the options supported by turf units (optional, default `"kilometers"`) + * `options.steps` **[number][4]** number of steps (optional, default `8`) + +### Examples ```javascript var point = turf.point([-90.548630, 14.616599]); @@ -30,7 +43,7 @@ var buffered = turf.buffer(point, 500, {units: 'miles'}); var addToMap = [point, buffered] ``` -Returns **([FeatureCollection][1] \| [Feature][3]<([Polygon][7] \| [MultiPolygon][8])> | [undefined][9])** buffered features +Returns **([FeatureCollection][1] | [Feature][3]<([Polygon][7] | [MultiPolygon][8])> | [undefined][9])** buffered features [1]: https://tools.ietf.org/html/rfc7946#section-3.3 diff --git a/packages/turf-buffer/index.js b/packages/turf-buffer/index.js index 60a367b7f9..35e41fb2a4 100644 --- a/packages/turf-buffer/index.js +++ b/packages/turf-buffer/index.js @@ -11,7 +11,18 @@ import { } from "@turf/helpers"; /** - * Calculates a buffer for input features for a given radius. Units supported are miles, kilometers, and degrees. + * Calculates a buffer for input features for a given radius. Units supported are: + * * centimeters or centimetres + * * degrees + * * feet + * * inches + * * kilometers or kilometres + * * meters, metres + * * miles + * * millimeters, millimetres + * * nauticalmiles + * * radians + * * yards * * When using a negative radius, the resulting geometry may be invalid if * it's too small compared to the radius magnitude. If the input is a