Skip to content

Commit

Permalink
Fixed disparities between jsdoc and function typedefs, mainly focused…
Browse files Browse the repository at this point in the history
… on Units and GeoJsonProperties. Also replaced a few more instances of Turf specific Id typedef, standardised wording of param descriptions (e.g. on Units, GeoJsonProperies). Updated example code to use const rather than var.
  • Loading branch information
smallsaucepan committed Dec 30, 2024
1 parent a8cbea3 commit 53a6c77
Show file tree
Hide file tree
Showing 87 changed files with 619 additions and 658 deletions.
14 changes: 7 additions & 7 deletions packages/turf-bbox-polygon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ Takes a bbox and returns an equivalent [polygon][1].

### Parameters

* `bbox` **[BBox][2]** extent in \[minX, minY, maxX, maxY] order
* `bbox` **[BBox][2]** Extent in \[minX, minY, maxX, maxY] order
* `options` **[Object][3]** Optional parameters (optional, default `{}`)

* `options.properties` **[GeoJsonProperties][4]** Translate properties to Polygon (optional, default `{}`)
* `options.id` **([string][5] | [number][6])** Translate Id to Polygon (optional, default `{}`)
* `options.properties` **[GeoJsonProperties][4]** Properties to set on returned feature (optional, default `{}`)
* `options.id` **([string][5] | [number][6])** Id to set on returned feature (optional, default `{}`)

### Examples

```javascript
var bbox = [0, 0, 10, 10];
const bbox = [0, 0, 10, 10];

var poly = turf.bboxPolygon(bbox);
const poly = turf.bboxPolygon(bbox);

//addToMap
var addToMap = [poly]
const addToMap = [poly]
```

Returns **[Feature][4]<[Polygon][1]>** a Polygon representation of the bounding box
Returns **[Feature][4]<[Polygon][1]>** Polygon representing the bounding box

[1]: https://tools.ietf.org/html/rfc7946#section-3.1.6

Expand Down
18 changes: 9 additions & 9 deletions packages/turf-bbox-polygon/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { BBox, Feature, Polygon, GeoJsonProperties } from "geojson";
import { polygon, Id } from "@turf/helpers";
import { polygon } from "@turf/helpers";

/**
* Takes a bbox and returns an equivalent {@link Polygon|polygon}.
*
* @function
* @param {BBox} bbox extent in [minX, minY, maxX, maxY] order
* @param {BBox} bbox Extent in [minX, minY, maxX, maxY] order
* @param {Object} [options={}] Optional parameters
* @param {GeoJsonProperties} [options.properties={}] Translate properties to Polygon
* @param {string|number} [options.id={}] Translate Id to Polygon
* @returns {Feature<Polygon>} a Polygon representation of the bounding box
* @param {GeoJsonProperties} [options.properties={}] Properties to set on returned feature
* @param {string|number} [options.id={}] Id to set on returned feature
* @returns {Feature<Polygon>} Polygon representing the bounding box
* @example
* var bbox = [0, 0, 10, 10];
* const bbox = [0, 0, 10, 10];
*
* var poly = turf.bboxPolygon(bbox);
* const poly = turf.bboxPolygon(bbox);
*
* //addToMap
* var addToMap = [poly]
* const addToMap = [poly]
*/
function bboxPolygon<P extends GeoJsonProperties = GeoJsonProperties>(
bbox: BBox,
options: {
properties?: P;
id?: Id;
id?: string | number;
} = {}
): Feature<Polygon, P> {
// Convert BBox positions to Numbers
Expand Down
16 changes: 8 additions & 8 deletions packages/turf-bezier-spline/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ The bezier spline implementation is by [Leszek Rybicki][3].

### Parameters

* `line` **[Feature][4]<[LineString][1]>** input LineString
* `line` **[Feature][4]<[LineString][1]>** Input LineString
* `options` **[Object][5]** Optional parameters (optional, default `{}`)

* `options.properties` **[Object][5]** Translate properties to output (optional, default `{}`)
* `options.resolution` **[number][6]** time in milliseconds between points (optional, default `10000`)
* `options.sharpness` **[number][6]** a measure of how curvy the path should be between splines (optional, default `0.85`)
* `options.properties` **[GeoJsonProperties][4]** Properties to set on returned feature (optional, default `{}`)
* `options.resolution` **[number][6]** Time in milliseconds between points (optional, default `10000`)
* `options.sharpness` **[number][6]** Measure of how curvy the path should be between splines (optional, default `0.85`)

### Examples

```javascript
var line = turf.lineString([
const line = turf.lineString([
[-76.091308, 18.427501],
[-76.695556, 18.729501],
[-76.552734, 19.40443],
Expand All @@ -31,14 +31,14 @@ var line = turf.lineString([
[-73.157958, 20.210656]
]);

var curved = turf.bezierSpline(line);
const curved = turf.bezierSpline(line);

//addToMap
var addToMap = [line, curved]
const addToMap = [line, curved]
curved.properties = { stroke: '#0F0' };
```

Returns **[Feature][4]<[LineString][1]>** curved line
Returns **[Feature][4]<[LineString][1]>** Curved line

[1]: https://tools.ietf.org/html/rfc7946#section-3.1.4

Expand Down
16 changes: 8 additions & 8 deletions packages/turf-bezier-spline/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import { Spline } from "./lib/spline.js";
* The bezier spline implementation is by [Leszek Rybicki](http://leszek.rybicki.cc/).
*
* @function
* @param {Feature<LineString>} line input LineString
* @param {Feature<LineString>} line Input LineString
* @param {Object} [options={}] Optional parameters
* @param {Object} [options.properties={}] Translate properties to output
* @param {number} [options.resolution=10000] time in milliseconds between points
* @param {number} [options.sharpness=0.85] a measure of how curvy the path should be between splines
* @returns {Feature<LineString>} curved line
* @param {GeoJsonProperties} [options.properties={}] Properties to set on returned feature
* @param {number} [options.resolution=10000] Time in milliseconds between points
* @param {number} [options.sharpness=0.85] Measure of how curvy the path should be between splines
* @returns {Feature<LineString>} Curved line
* @example
* var line = turf.lineString([
* const line = turf.lineString([
* [-76.091308, 18.427501],
* [-76.695556, 18.729501],
* [-76.552734, 19.40443],
Expand All @@ -27,10 +27,10 @@ import { Spline } from "./lib/spline.js";
* [-73.157958, 20.210656]
* ]);
*
* var curved = turf.bezierSpline(line);
* const curved = turf.bezierSpline(line);
*
* //addToMap
* var addToMap = [line, curved]
* const addToMap = [line, curved]
* curved.properties = { stroke: '#0F0' };
*/
function bezierSpline<P extends GeoJsonProperties = GeoJsonProperties>(
Expand Down
2 changes: 1 addition & 1 deletion packages/turf-boolean-intersects/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Boolean-intersects returns (TRUE) if the intersection of the two geometries is N
* `feature2` **([Geometry][1] | [Feature][2]\<any>)** GeoJSON Feature or Geometry
* `options` **[Object][3]** Optional parameters (optional, default `{}`)

* `options.ignoreSelfIntersections` **[boolean][4]** ignores self-intersections on input features (optional, default `false`)
* `options.ignoreSelfIntersections` **[boolean][4]** ignore self-intersections on input features (optional, default `true`)

### Examples

Expand Down
24 changes: 11 additions & 13 deletions packages/turf-buffer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ the input, or even be empty.

### 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)
* `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`)
* `options.units` **Units** Units in which linear values are expressed (optional, default `"kilometers"`)
* `options.steps` **[number][4]** Number of steps (optional, default `8`)

### Examples

```javascript
var point = turf.point([-90.548630, 14.616599]);
var buffered = turf.buffer(point, 500, {units: 'miles'});
const point = turf.point([-90.548630, 14.616599]);
const buffered = turf.buffer(point, 500, {units: 'miles'});

//addToMap
var addToMap = [point, buffered]
const addToMap = [point, buffered]
```

Returns **([FeatureCollection][1] | [Feature][3]<([Polygon][7] | [MultiPolygon][8])> | [undefined][9])** buffered features
Returns **([FeatureCollection][1] | [Feature][3]<([Polygon][6] | [MultiPolygon][7])> | [undefined][8])** Buffered features

[1]: https://tools.ietf.org/html/rfc7946#section-3.3

Expand All @@ -43,13 +43,11 @@ Returns **([FeatureCollection][1] | [Feature][3]<([Polygon][7] | [MultiPolygon][

[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object

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

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

[8]: https://tools.ietf.org/html/rfc7946#section-3.1.7

[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined

<!-- 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. -->

Expand Down
16 changes: 8 additions & 8 deletions packages/turf-buffer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ const { BufferOp, GeoJSONReader, GeoJSONWriter } = jsts;
* the input, or even be empty.
*
* @function
* @param {FeatureCollection|Geometry|Feature<any>} geojson input to be buffered
* @param {number} radius distance to draw the buffer (negative values are allowed)
* @param {FeatureCollection|Geometry|Feature<any>} geojson Input to be buffered
* @param {number} radius Distance to draw the buffer (negative values are allowed)
* @param {Object} [options={}] Optional parameters
* @param {string} [options.units="kilometers"] any of the options supported by turf units
* @param {number} [options.steps=8] number of steps
* @returns {FeatureCollection|Feature<Polygon|MultiPolygon>|undefined} buffered features
* @param {Units} [options.units="kilometers"] Units in which linear values are expressed
* @param {number} [options.steps=8] Number of steps
* @returns {FeatureCollection|Feature<Polygon|MultiPolygon>|undefined} Buffered features
* @example
* var point = turf.point([-90.548630, 14.616599]);
* var buffered = turf.buffer(point, 500, {units: 'miles'});
* const point = turf.point([-90.548630, 14.616599]);
* const buffered = turf.buffer(point, 500, {units: 'miles'});
*
* //addToMap
* var addToMap = [point, buffered]
* const addToMap = [point, buffered]
*/
function buffer(geojson, radius, options) {
// Optional params
Expand Down
26 changes: 15 additions & 11 deletions packages/turf-center-mean/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@ Takes a [Feature][1] or [FeatureCollection][2] and returns the mean center. Can
* `geojson` **[GeoJSON][3]** GeoJSON to be centered
* `options` **[Object][4]** Optional parameters (optional, default `{}`)

* `options.properties` **[Object][4]** Translate GeoJSON Properties to Point (optional, default `{}`)
* `options.bbox` **[Object][4]** Translate GeoJSON BBox to Point (optional, default `{}`)
* `options.id` **[Object][4]** Translate GeoJSON Id to Point (optional, default `{}`)
* `options.weight` **[string][5]?** the property name used to weight the center
* `options.properties` **[GeoJsonProperties][1]** Properties to set on returned feature (optional, default `{}`)
* `options.bbox` **[BBox][5]** TranslBBox to set on returned feature (optional, default `{}`)
* `options.id` **([string][6] | [number][7])** Id to set on returned feature (optional, default `{}`)
* `options.weight` **[string][6]?** Property name used to weight the center

### Examples

```javascript
var features = turf.featureCollection([
const features = turf.featureCollection([
turf.point([-97.522259, 35.4691], {value: 10}),
turf.point([-97.502754, 35.463455], {value: 3}),
turf.point([-97.508269, 35.463245], {value: 5})
]);

var options = {weight: "value"}
var mean = turf.centerMean(features, options);
const options = {weight: "value"}
const mean = turf.centerMean(features, options);

//addToMap
var addToMap = [features, mean]
const addToMap = [features, mean]
mean.properties['marker-size'] = 'large';
mean.properties['marker-color'] = '#000';
```

Returns **[Feature][1]<[Point][6]>** a Point feature at the mean center point of all input features
Returns **[Feature][1]<[Point][8]>** Point feature at the mean center point of all input features

[1]: https://tools.ietf.org/html/rfc7946#section-3.2

Expand All @@ -44,9 +44,13 @@ Returns **[Feature][1]<[Point][6]>** a Point feature at the mean center point of

[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object

[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[5]: https://tools.ietf.org/html/rfc7946#section-5

[6]: https://tools.ietf.org/html/rfc7946#section-3.1.2
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String

[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number

[8]: https://tools.ietf.org/html/rfc7946#section-3.1.2

<!-- 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. -->

Expand Down
27 changes: 16 additions & 11 deletions packages/turf-center-mean/index.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@
import { BBox, Feature, Point, GeoJsonProperties } from "geojson";
import { geomEach, coordEach } from "@turf/meta";
import { isNumber, point, Id } from "@turf/helpers";
import { isNumber, point } from "@turf/helpers";

/**
* Takes a {@link Feature} or {@link FeatureCollection} and returns the mean center. Can be weighted.
*
* @function
* @param {GeoJSON} geojson GeoJSON to be centered
* @param {Object} [options={}] Optional parameters
* @param {Object} [options.properties={}] Translate GeoJSON Properties to Point
* @param {Object} [options.bbox={}] Translate GeoJSON BBox to Point
* @param {Object} [options.id={}] Translate GeoJSON Id to Point
* @param {string} [options.weight] the property name used to weight the center
* @returns {Feature<Point>} a Point feature at the mean center point of all input features
* @param {GeoJsonProperties} [options.properties={}] Properties to set on returned feature
* @param {BBox} [options.bbox={}] TranslBBox to set on returned feature
* @param {string | number} [options.id={}] Id to set on returned feature
* @param {string} [options.weight] Property name used to weight the center
* @returns {Feature<Point>} Point feature at the mean center point of all input features
* @example
* var features = turf.featureCollection([
* const features = turf.featureCollection([
* turf.point([-97.522259, 35.4691], {value: 10}),
* turf.point([-97.502754, 35.463455], {value: 3}),
* turf.point([-97.508269, 35.463245], {value: 5})
* ]);
*
* var options = {weight: "value"}
* var mean = turf.centerMean(features, options);
* const options = {weight: "value"}
* const mean = turf.centerMean(features, options);
*
* //addToMap
* var addToMap = [features, mean]
* const addToMap = [features, mean]
* mean.properties['marker-size'] = 'large';
* mean.properties['marker-color'] = '#000';
*/
function centerMean<P extends GeoJsonProperties = GeoJsonProperties>(
geojson: any, // To-Do include Typescript AllGeoJSON
options: { properties?: P; bbox?: BBox; id?: Id; weight?: string } = {}
options: {
properties?: P;
bbox?: BBox;
id?: string | number;
weight?: string;
} = {}
): Feature<Point, P> {
let sumXs = 0;
let sumYs = 0;
Expand Down
8 changes: 4 additions & 4 deletions packages/turf-center-of-mass/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ Takes any [Feature][1] or a [FeatureCollection][2] and returns its [center of ma
* `geojson` **[GeoJSON][5]** GeoJSON to be centered
* `options` **[Object][6]** Optional Parameters (optional, default `{}`)

* `options.properties` **[Object][6]** Translate Properties to Feature (optional, default `{}`)
* `options.properties` **[GeoJsonProperties][1]** Properties to set on returned feature (optional, default `{}`)

### Examples

```javascript
var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);
const polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);

var center = turf.centerOfMass(polygon);
const center = turf.centerOfMass(polygon);

//addToMap
var addToMap = [polygon, center]
const addToMap = [polygon, center]
```

Returns **[Feature][1]<[Point][7]>** the center of mass
Expand Down
8 changes: 4 additions & 4 deletions packages/turf-center-of-mass/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import { coordEach } from "@turf/meta";
* @function
* @param {GeoJSON} geojson GeoJSON to be centered
* @param {Object} [options={}] Optional Parameters
* @param {Object} [options.properties={}] Translate Properties to Feature
* @param {GeoJsonProperties} [options.properties={}] Properties to set on returned feature
* @returns {Feature<Point>} the center of mass
* @example
* var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);
* const polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);
*
* var center = turf.centerOfMass(polygon);
* const center = turf.centerOfMass(polygon);
*
* //addToMap
* var addToMap = [polygon, center]
* const addToMap = [polygon, center]
*/
function centerOfMass<P extends GeoJsonProperties = GeoJsonProperties>(
geojson: any,
Expand Down
Loading

0 comments on commit 53a6c77

Please sign in to comment.