Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify behavior of some existing turf modules #2683

Merged
merged 11 commits into from
Aug 9, 2024
4 changes: 2 additions & 2 deletions packages/turf-area/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { earthRadius } from "@turf/helpers";
import { geomReduce } from "@turf/meta";

/**
* Takes one or more features and returns their area in square meters.
* Calculates the geodesic area in square meters of one or more polygons.
*
* @name area
* @param {GeoJSON} geojson input GeoJSON feature(s)
* @param {GeoJSON} geojson input polygon(s) as {@link Geometry}, {@link Feature}, or {@link FeatureCollection}
* @returns {number} area in square meters
* @example
* var polygon = turf.polygon([[[125, -15], [113, -22], [154, -27], [144, -15], [125, -15]]]);
Expand Down
8 changes: 5 additions & 3 deletions packages/turf-helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,17 @@ export type AllGeoJSON =
*/

/**
* Earth Radius used with the Harvesine formula and approximates using a spherical (non-ellipsoid) Earth.
*
* The {@link https://en.wikipedia.org/wiki/Earth_radius#Arithmetic_mean_radius arithmetic mean radius} of the Earth.
* Used by Turf modules that model the Earth as a sphere. This radii value
* was chosen over others because it is {@link https://rosettacode.org/wiki/Haversine_formula#:~:text=This%20value%20is%20recommended recommended for use} with the Haversine formula,
* used by turf/distance.
smallsaucepan marked this conversation as resolved.
Show resolved Hide resolved
* @memberof helpers
* @type {number}
*/
export const earthRadius = 6371008.8;

/**
* Unit of measurement factors using a spherical (non-ellipsoid) earth radius.
* Unit of measurement factors based on equatorial earthRadius.
twelch marked this conversation as resolved.
Show resolved Hide resolved
*
* Keys are the name of the unit, values are the number of that unit in a single radian
*
Expand Down
8 changes: 4 additions & 4 deletions packages/turf-point-grid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import { distance } from "@turf/distance";
import { point, featureCollection, Units } from "@turf/helpers";

/**
* Creates a {@link Point} grid from a bounding box, {@link FeatureCollection} or {@link Feature}.
* Creates a grid of points
*
* @name pointGrid
* @param {Array<number>} bbox extent in [minX, minY, maxX, maxY] order
* @param {number} cellSide the distance between points, in units
* @param {Array<number>} bbox extent of grid in [minX, minY, maxX, maxY] order
twelch marked this conversation as resolved.
Show resolved Hide resolved
* @param {number} cellSide the distance between points
* @param {Object} [options={}] Optional parameters
* @param {string} [options.units='kilometers'] used in calculating cellSide, can be degrees, radians, miles, or kilometers
* @param {string} [options.units='kilometers'] the units of the cellSide value. Supports all valid Turf {@link https://github.com/Turfjs/turf/blob/master/packages/turf-helpers/index.ts Units}
* @param {Feature<Polygon|MultiPolygon>} [options.mask] if passed a Polygon or MultiPolygon, the grid Points will be created only inside it
* @param {Object} [options.properties={}] passed to each point of the grid
* @returns {FeatureCollection<Point>} grid of points
Expand Down
11 changes: 5 additions & 6 deletions packages/turf-rectangle-grid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ import {
Units,
} from "@turf/helpers";
/**
* Creates a grid of rectangles from a bounding box, {@link Feature} or {@link FeatureCollection}.
* Creates a grid of rectangular polygon cells of equal width and height in degrees.
twelch marked this conversation as resolved.
Show resolved Hide resolved
*
* @name rectangleGrid
* @param {Array<number>} bbox extent in [minX, minY, maxX, maxY] order
* @param {number} cellWidth of each cell, in units
* @param {number} cellHeight of each cell, in units
* @param {Array<number>} bbox extent of grid in [minX, minY, maxX, maxY] order. If the grid does not fill the bbox perfectly, it is centered.
* @param {number} cellWidth width of each cell, in units
* @param {number} cellHeight height of each cell, in units
* @param {Object} [options={}] Optional parameters
* @param {string} [options.units='kilometers'] units ("degrees", "radians", "miles", "kilometers") that the given cellWidth
* and cellHeight are expressed in. Converted at the southern border.
* @param {string} [options.units='kilometers'] the units of the cellWidth and cellLenth values. Supports all valid Turf {@link https://github.com/Turfjs/turf/blob/master/packages/turf-helpers/index.ts Units}. Internally cellWidth and cellLength values are converted to degrees, regardless of units specified.
* @param {Feature<Polygon|MultiPolygon>} [options.mask] if passed a Polygon or MultiPolygon,
* the grid Points will be created only inside it
* @param {Object} [options.properties={}] passed to each point of the grid
Expand Down
10 changes: 5 additions & 5 deletions packages/turf-square-grid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ import { Units } from "@turf/helpers";
import { rectangleGrid } from "@turf/rectangle-grid";

/**
* Creates a square grid from a bounding box.
* Creates a grid of square polygon cells with equal length sides in degrees.
*
* @name squareGrid
* @param {Array<number>} bbox extent in [minX, minY, maxX, maxY] order
* @param {number} cellSide of each cell, in units
* @param {Array<number>} bbox extent of grid in [minX, minY, maxX, maxY] order. If the grid does not fill the bbox perfectly, it is centered.
* @param {number} cellSide length of each cell side.
* @param {Object} [options={}] Optional parameters
* @param {string} [options.units='kilometers'] used in calculating cellSide, can be degrees,
* @param {string} [options.units='kilometers'] the units of the cellSide value. Supports all valid Turf {@link https://github.com/Turfjs/turf/blob/master/packages/turf-helpers/index.ts Units}. Internally cellSide value is converted to degrees, regardless of units specified.
twelch marked this conversation as resolved.
Show resolved Hide resolved
* radians, miles, or kilometers
* @param {Feature<Polygon|MultiPolygon>} [options.mask] if passed a Polygon or MultiPolygon,
* the grid Points will be created only inside it
* @param {Object} [options.properties={}] passed to each point of the grid
* @returns {FeatureCollection<Polygon>} grid a grid of polygons
* @returns {FeatureCollection<Polygon>} a grid of polygons with equal width and height in degrees.
* @example
* var bbox = [-95, 30 ,-85, 40];
* var cellSide = 50;
Expand Down
8 changes: 4 additions & 4 deletions packages/turf-triangle-grid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { intersect } from "@turf/intersect";
import { polygon, featureCollection, Units } from "@turf/helpers";

/**
* Takes a bounding box and a cell depth and returns a set of triangular {@link Polygon|polygons} in a grid.
* Creates a grid of triangular polygons.
*
* @name triangleGrid
* @param {Array<number>} bbox extent in [minX, minY, maxX, maxY] order
* @param {number} cellSide dimension of each cell
* @param {Array<number>} bbox extent of grid in [minX, minY, maxX, maxY] order
* @param {number} cellSide dimension of each grid cell. Two triangles are created in each cell.
* @param {Object} [options={}] Optional parameters
* @param {string} [options.units='kilometers'] used in calculating cellSide, can be degrees, radians, miles, or kilometers
* @param {string} [options.units='kilometers'] used in calculating cellSide. Supports all valid Turf {@link https://github.com/Turfjs/turf/blob/master/packages/turf-helpers/index.ts Units}
twelch marked this conversation as resolved.
Show resolved Hide resolved
* @param {Feature<Polygon>} [options.mask] if passed a Polygon or MultiPolygon, the grid Points will be created only inside it
* @param {Object} [options.properties={}] passed to each point of the grid
* @returns {FeatureCollection<Polygon>} grid of polygons
Expand Down