Skip to content

Commit 5f0d405

Browse files
authored
Clarify behavior of some existing turf modules (#2683)
* update turf-rectangle-grid and turf-square-grid docs * improve area docs * cleanup * update earthRadius, first crack at units link, other nits * improve docs * nit * add readme units file * update area readme manually * one more readme * update all readmes
1 parent ad8012c commit 5f0d405

13 files changed

Lines changed: 282 additions & 228 deletions

File tree

packages/turf-area/README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
## area
66

7-
Takes one or more features and returns their area in square meters.
7+
Calculates the geodesic area in square meters of one or more polygons.
88

99
### Parameters
1010

11-
* `geojson` **[GeoJSON][1]** input GeoJSON feature(s)
11+
* `geojson` **[GeoJSON][1]** input polygon(s) as [Geometry][2], [Feature][3], or [FeatureCollection][4]
1212

1313
### Examples
1414

@@ -22,11 +22,17 @@ var addToMap = [polygon]
2222
polygon.properties.area = area
2323
```
2424

25-
Returns **[number][2]** area in square meters
25+
Returns **[number][5]** area in square meters
2626

2727
[1]: https://tools.ietf.org/html/rfc7946#section-3
2828

29-
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
29+
[2]: https://tools.ietf.org/html/rfc7946#section-3.1
30+
31+
[3]: https://tools.ietf.org/html/rfc7946#section-3.2
32+
33+
[4]: https://tools.ietf.org/html/rfc7946#section-3.3
34+
35+
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
3036

3137
<!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. -->
3238

packages/turf-area/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { earthRadius } from "@turf/helpers";
33
import { geomReduce } from "@turf/meta";
44

55
/**
6-
* Takes one or more features and returns their area in square meters.
6+
* Calculates the geodesic area in square meters of one or more polygons.
77
*
88
* @name area
9-
* @param {GeoJSON} geojson input GeoJSON feature(s)
9+
* @param {GeoJSON} geojson input polygon(s) as {@link Geometry}, {@link Feature}, or {@link FeatureCollection}
1010
* @returns {number} area in square meters
1111
* @example
1212
* var polygon = turf.polygon([[[125, -15], [113, -22], [154, -27], [144, -15], [125, -15]]]);

packages/turf-helpers/README.md

Lines changed: 146 additions & 142 deletions
Large diffs are not rendered by default.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# @turf/helpers
2+
3+
## Units
4+
5+
* meters
6+
* metres
7+
* millimeters
8+
* millimetres
9+
* centimeters
10+
* centimetres
11+
* kilometers
12+
* kilometres
13+
* miles
14+
* nauticalmiles
15+
* inches
16+
* yards
17+
* feet
18+
* radians
19+
* degrees
20+
21+
## AreaUnits
22+
23+
* meters
24+
* metres
25+
* millimeters
26+
* millimetres
27+
* centimeters
28+
* centimetres
29+
* kilometers
30+
* kilometres
31+
* miles
32+
* nauticalmiles
33+
* inches
34+
* yards
35+
* feet
36+
* acres
37+
* hectares

packages/turf-helpers/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,14 @@ export type AllGeoJSON =
5757
*/
5858

5959
/**
60-
* Earth Radius used with the Harvesine formula and approximates using a spherical (non-ellipsoid) Earth.
61-
*
60+
* The Earth radius in kilometers. Used by Turf modules that model the Earth as a sphere. The {@link https://en.wikipedia.org/wiki/Earth_radius#Arithmetic_mean_radius mean radius} was selected because it is {@link https://rosettacode.org/wiki/Haversine_formula#:~:text=This%20value%20is%20recommended recommended } by the Haversine formula (used by turf/distance) to reduce error.
6261
* @memberof helpers
6362
* @type {number}
6463
*/
6564
export const earthRadius = 6371008.8;
6665

6766
/**
68-
* Unit of measurement factors using a spherical (non-ellipsoid) earth radius.
67+
* Unit of measurement factors based on earthRadius.
6968
*
7069
* Keys are the name of the unit, values are the number of that unit in a single radian
7170
*

packages/turf-point-grid/README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44

55
## pointGrid
66

7-
Creates a [Point][1] grid from a bounding box, [FeatureCollection][2] or [Feature][3].
7+
Creates a grid of points
88

99
### Parameters
1010

11-
* `bbox` **[Array][4]<[number][5]>** extent in \[minX, minY, maxX, maxY] order
12-
* `cellSide` **[number][5]** the distance between points, in units
13-
* `options` **[Object][6]** Optional parameters (optional, default `{}`)
11+
* `bbox` **[BBox][1]** extent of grid in \[minX, minY, maxX, maxY] order
12+
* `cellSide` **[number][2]** the distance between points
13+
* `options` **[Object][3]** Optional parameters (optional, default `{}`)
1414

15-
* `options.units` **[string][7]** used in calculating cellSide, can be degrees, radians, miles, or kilometers (optional, default `'kilometers'`)
16-
* `options.mask` **[Feature][3]<([Polygon][8] | [MultiPolygon][9])>?** if passed a Polygon or MultiPolygon, the grid Points will be created only inside it
17-
* `options.properties` **[Object][6]** passed to each point of the grid (optional, default `{}`)
15+
* `options.units` **Units** the units of the cellSide value. Supports all valid Turf [Units][4] (optional, default `'kilometers'`)
16+
* `options.mask` **[Feature][5]<([Polygon][6] | [MultiPolygon][7])>?** if passed a Polygon or MultiPolygon, the grid Points will be created only inside it
17+
* `options.properties` **[Object][3]** passed to each point of the grid (optional, default `{}`)
1818

1919
### Examples
2020

@@ -29,25 +29,25 @@ var grid = turf.pointGrid(extent, cellSide, options);
2929
var addToMap = [grid];
3030
```
3131

32-
Returns **[FeatureCollection][2]<[Point][1]>** grid of points
32+
Returns **[FeatureCollection][8]<[Point][9]>** grid of points
3333

34-
[1]: https://tools.ietf.org/html/rfc7946#section-3.1.2
34+
[1]: https://tools.ietf.org/html/rfc7946#section-5
3535

36-
[2]: https://tools.ietf.org/html/rfc7946#section-3.3
36+
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
3737

38-
[3]: https://tools.ietf.org/html/rfc7946#section-3.2
38+
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
3939

40-
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
40+
[4]: https://github.com/Turfjs/turf/blob/master/packages/turf-helpers/README_UNITS.md
4141

42-
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
42+
[5]: https://tools.ietf.org/html/rfc7946#section-3.2
4343

44-
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
44+
[6]: https://tools.ietf.org/html/rfc7946#section-3.1.6
4545

46-
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
46+
[7]: https://tools.ietf.org/html/rfc7946#section-3.1.7
4747

48-
[8]: https://tools.ietf.org/html/rfc7946#section-3.1.6
48+
[8]: https://tools.ietf.org/html/rfc7946#section-3.3
4949

50-
[9]: https://tools.ietf.org/html/rfc7946#section-3.1.7
50+
[9]: https://tools.ietf.org/html/rfc7946#section-3.1.2
5151

5252
<!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. -->
5353

packages/turf-point-grid/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import { distance } from "@turf/distance";
1212
import { point, featureCollection, Units } from "@turf/helpers";
1313

1414
/**
15-
* Creates a {@link Point} grid from a bounding box, {@link FeatureCollection} or {@link Feature}.
15+
* Creates a grid of points
1616
*
1717
* @name pointGrid
18-
* @param {Array<number>} bbox extent in [minX, minY, maxX, maxY] order
19-
* @param {number} cellSide the distance between points, in units
18+
* @param {BBox} bbox extent of grid in [minX, minY, maxX, maxY] order
19+
* @param {number} cellSide the distance between points
2020
* @param {Object} [options={}] Optional parameters
21-
* @param {string} [options.units='kilometers'] used in calculating cellSide, can be degrees, radians, miles, or kilometers
21+
* @param {Units} [options.units='kilometers'] the units of the cellSide value. Supports all valid Turf {@link https://github.com/Turfjs/turf/blob/master/packages/turf-helpers/README_UNITS.md Units}
2222
* @param {Feature<Polygon|MultiPolygon>} [options.mask] if passed a Polygon or MultiPolygon, the grid Points will be created only inside it
2323
* @param {Object} [options.properties={}] passed to each point of the grid
2424
* @returns {FeatureCollection<Point>} grid of points

packages/turf-rectangle-grid/README.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@
44

55
## rectangleGrid
66

7-
Creates a grid of rectangles from a bounding box, [Feature][1] or [FeatureCollection][2].
7+
Creates a grid of rectangular polygons with width and height consistent in degrees
88

99
### Parameters
1010

11-
* `bbox` **[Array][3]<[number][4]>** extent in \[minX, minY, maxX, maxY] order
12-
* `cellWidth` **[number][4]** of each cell, in units
13-
* `cellHeight` **[number][4]** of each cell, in units
14-
* `options` **[Object][5]** Optional parameters (optional, default `{}`)
11+
* `bbox` **[BBox][1]** extent of grid in \[minX, minY, maxX, maxY] order. If the grid does not fill the bbox perfectly, it is centered.
12+
* `cellWidth` **[number][2]** width of each cell, in units
13+
* `cellHeight` **[number][2]** height of each cell, in units
14+
* `options` **[Object][3]** Optional parameters (optional, default `{}`)
1515

16-
* `options.units` **[string][6]** units ("degrees", "radians", "miles", "kilometers") that the given cellWidth
17-
and cellHeight are expressed in. Converted at the southern border. (optional, default `'kilometers'`)
18-
* `options.mask` **[Feature][1]<([Polygon][7] | [MultiPolygon][8])>?** if passed a Polygon or MultiPolygon,
16+
* `options.units` **Units** the units of the cell width and height value.
17+
Supports all valid Turf [Units][4].
18+
If you are looking for rectangles with equal width and height in linear units (e.g. kilometers) this is not the module for you.
19+
The cellWidth and cellHeight is converted from units provided to degrees internally, so the width and height of resulting polygons will be consistent only in degrees. (optional, default `'kilometers'`)
20+
* `options.mask` **[Feature][5]<([Polygon][6] | [MultiPolygon][7])>?** if passed a Polygon or MultiPolygon,
1921
the grid Points will be created only inside it
20-
* `options.properties` **[Object][5]** passed to each point of the grid (optional, default `{}`)
22+
* `options.properties` **[Object][3]** passed to each point of the grid (optional, default `{}`)
2123

2224
### Examples
2325

@@ -33,23 +35,23 @@ var rectangleGrid = turf.rectangleGrid(bbox, cellWidth, cellHeight, options);
3335
var addToMap = [rectangleGrid]
3436
```
3537

36-
Returns **[FeatureCollection][2]<[Polygon][7]>** a grid of polygons
38+
Returns **[FeatureCollection][8]<[Polygon][6]>** a grid of polygons
3739

38-
[1]: https://tools.ietf.org/html/rfc7946#section-3.2
40+
[1]: https://tools.ietf.org/html/rfc7946#section-5
3941

40-
[2]: https://tools.ietf.org/html/rfc7946#section-3.3
42+
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
4143

42-
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
44+
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
4345

44-
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
46+
[4]: https://github.com/Turfjs/turf/blob/master/packages/turf-helpers/README_UNITS.md
4547

46-
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
48+
[5]: https://tools.ietf.org/html/rfc7946#section-3.2
4749

48-
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
50+
[6]: https://tools.ietf.org/html/rfc7946#section-3.1.6
4951

50-
[7]: https://tools.ietf.org/html/rfc7946#section-3.1.6
52+
[7]: https://tools.ietf.org/html/rfc7946#section-3.1.7
5153

52-
[8]: https://tools.ietf.org/html/rfc7946#section-3.1.7
54+
[8]: https://tools.ietf.org/html/rfc7946#section-3.3
5355

5456
<!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. -->
5557

packages/turf-rectangle-grid/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ import {
1414
Units,
1515
} from "@turf/helpers";
1616
/**
17-
* Creates a grid of rectangles from a bounding box, {@link Feature} or {@link FeatureCollection}.
17+
* Creates a grid of rectangular polygons with width and height consistent in degrees
1818
*
1919
* @name rectangleGrid
20-
* @param {Array<number>} bbox extent in [minX, minY, maxX, maxY] order
21-
* @param {number} cellWidth of each cell, in units
22-
* @param {number} cellHeight of each cell, in units
20+
* @param {BBox} bbox extent of grid in [minX, minY, maxX, maxY] order. If the grid does not fill the bbox perfectly, it is centered.
21+
* @param {number} cellWidth width of each cell, in units
22+
* @param {number} cellHeight height of each cell, in units
2323
* @param {Object} [options={}] Optional parameters
24-
* @param {string} [options.units='kilometers'] units ("degrees", "radians", "miles", "kilometers") that the given cellWidth
25-
* and cellHeight are expressed in. Converted at the southern border.
24+
* @param {Units} [options.units='kilometers'] the units of the cell width and height value.
25+
* Supports all valid Turf {@link https://github.com/Turfjs/turf/blob/master/packages/turf-helpers/README_UNITS.md Units}.
26+
* If you are looking for rectangles with equal width and height in linear units (e.g. kilometers) this is not the module for you.
27+
* The cellWidth and cellHeight is converted from units provided to degrees internally, so the width and height of resulting polygons will be consistent only in degrees.
2628
* @param {Feature<Polygon|MultiPolygon>} [options.mask] if passed a Polygon or MultiPolygon,
2729
* the grid Points will be created only inside it
2830
* @param {Object} [options.properties={}] passed to each point of the grid

packages/turf-square-grid/README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44

55
## squareGrid
66

7-
Creates a square grid from a bounding box.
7+
Creates a grid of square polygons with cell length consistent in degrees
88

99
### Parameters
1010

11-
* `bbox` **[Array][1]<[number][2]>** extent in \[minX, minY, maxX, maxY] order
12-
* `cellSide` **[number][2]** of each cell, in units
11+
* `bbox` **[BBox][1]** extent of grid in \[minX, minY, maxX, maxY] order. If the grid does not fill the bbox perfectly, it is centered.
12+
* `cellSide` **[number][2]** length of each cell side.
1313
* `options` **[Object][3]** Optional parameters (optional, default `{}`)
1414

15-
* `options.units` **[string][4]** used in calculating cellSide, can be degrees,
16-
radians, miles, or kilometers (optional, default `'kilometers'`)
15+
* `options.units` **Units** the units of the cellSide value.
16+
Supports all valid Turf [Units][4].
17+
If you are looking for squares with sides of equal lengths in linear units (e.g. kilometers) this is not the module for you.
18+
The cellSide is converted from units provided to degrees internally, so the width and height of resulting polygons will be consistent only in degrees. (optional, default `'kilometers'`)
1719
* `options.mask` **[Feature][5]<([Polygon][6] | [MultiPolygon][7])>?** if passed a Polygon or MultiPolygon,
1820
the grid Points will be created only inside it
1921
* `options.properties` **[Object][3]** passed to each point of the grid (optional, default `{}`)
@@ -31,15 +33,15 @@ var squareGrid = turf.squareGrid(bbox, cellSide, options);
3133
var addToMap = [squareGrid]
3234
```
3335

34-
Returns **[FeatureCollection][8]<[Polygon][6]>** grid a grid of polygons
36+
Returns **[FeatureCollection][8]<[Polygon][6]>** a grid of polygons with equal width and height in degrees.
3537

36-
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
38+
[1]: https://tools.ietf.org/html/rfc7946#section-5
3739

3840
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
3941

4042
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
4143

42-
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
44+
[4]: https://github.com/Turfjs/turf/blob/master/packages/turf-helpers/README_UNITS.md
4345

4446
[5]: https://tools.ietf.org/html/rfc7946#section-3.2
4547

0 commit comments

Comments
 (0)