Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@turf/meta

Package Overview
Dependencies
Maintainers
9
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/meta - npm Package Compare versions

Comparing version
7.3.1
to
7.3.2
+188
-95
dist/cjs/index.cjs

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.js
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
var _helpers = require('@turf/helpers');

@@ -7,3 +7,9 @@ function coordEach(geojson, callback, excludeWrapCoord) {

for (var featureIndex = 0; featureIndex < stop; featureIndex++) {
geometryMaybeCollection = isFeatureCollection ? geojson.features[featureIndex].geometry : isFeature ? geojson.geometry : geojson;
geometryMaybeCollection = isFeatureCollection ? (
// @ts-expect-error: Known type conflict
geojson.features[featureIndex].geometry
) : isFeature ? (
// @ts-expect-error: Known type conflict
geojson.geometry
) : geojson;
isGeometryCollection = geometryMaybeCollection ? geometryMaybeCollection.type === "GeometryCollection" : false;

@@ -23,9 +29,12 @@ stopG = isGeometryCollection ? geometryMaybeCollection.geometries.length : 1;

case "Point":
if (callback(
coords,
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) === false)
if (
// @ts-expect-error: Known type conflict
callback(
coords,
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) === false
)
return false;

@@ -38,9 +47,12 @@ coordIndex++;

for (j = 0; j < coords.length; j++) {
if (callback(
coords[j],
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) === false)
if (
// @ts-expect-error: Known type conflict
callback(
coords[j],
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) === false
)
return false;

@@ -56,9 +68,12 @@ coordIndex++;

for (k = 0; k < coords[j].length - wrapShrink; k++) {
if (callback(
coords[j][k],
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) === false)
if (
// @ts-expect-error: Known type conflict
callback(
coords[j][k],
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) === false
)
return false;

@@ -77,9 +92,12 @@ coordIndex++;

for (l = 0; l < coords[j][k].length - wrapShrink; l++) {
if (callback(
coords[j][k][l],
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) === false)
if (
// @ts-expect-error: Known type conflict
callback(
coords[j][k][l],
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) === false
)
return false;

@@ -95,3 +113,6 @@ coordIndex++;

for (j = 0; j < geometry.geometries.length; j++)
if (coordEach(geometry.geometries[j], callback, excludeWrapCoord) === false)
if (
// @ts-expect-error: Known type conflict
coordEach(geometry.geometries[j], callback, excludeWrapCoord) === false
)
return false;

@@ -114,2 +135,3 @@ break;

previousValue = callback(
// @ts-expect-error: Known type conflict
previousValue,

@@ -178,6 +200,30 @@ currentCoord,

for (i = 0; i < stop; i++) {
geometryMaybeCollection = isFeatureCollection ? geojson.features[i].geometry : isFeature ? geojson.geometry : geojson;
featureProperties = isFeatureCollection ? geojson.features[i].properties : isFeature ? geojson.properties : {};
featureBBox = isFeatureCollection ? geojson.features[i].bbox : isFeature ? geojson.bbox : void 0;
featureId = isFeatureCollection ? geojson.features[i].id : isFeature ? geojson.id : void 0;
geometryMaybeCollection = isFeatureCollection ? (
// @ts-expect-error: Known type conflict
geojson.features[i].geometry
) : isFeature ? (
// @ts-expect-error: Known type conflict
geojson.geometry
) : geojson;
featureProperties = isFeatureCollection ? (
// @ts-expect-error: Known type conflict
geojson.features[i].properties
) : isFeature ? (
// @ts-expect-error: Known type conflict
geojson.properties
) : {};
featureBBox = isFeatureCollection ? (
// @ts-expect-error: Known type conflict
geojson.features[i].bbox
) : isFeature ? (
// @ts-expect-error: Known type conflict
geojson.bbox
) : void 0;
featureId = isFeatureCollection ? (
// @ts-expect-error: Known type conflict
geojson.features[i].id
) : isFeature ? (
// @ts-expect-error: Known type conflict
geojson.id
) : void 0;
isGeometryCollection = geometryMaybeCollection ? geometryMaybeCollection.type === "GeometryCollection" : false;

@@ -188,9 +234,13 @@ stopG = isGeometryCollection ? geometryMaybeCollection.geometries.length : 1;

if (geometry === null) {
if (callback(
null,
featureIndex,
featureProperties,
featureBBox,
featureId
) === false)
if (
// @ts-expect-error: Known type conflict
callback(
// @ts-expect-error: Known type conflict
null,
featureIndex,
featureProperties,
featureBBox,
featureId
) === false
)
return false;

@@ -206,9 +256,12 @@ continue;

case "MultiPolygon": {
if (callback(
geometry,
featureIndex,
featureProperties,
featureBBox,
featureId
) === false)
if (
// @ts-expect-error: Known type conflict
callback(
geometry,
featureIndex,
featureProperties,
featureBBox,
featureId
) === false
)
return false;

@@ -219,9 +272,12 @@ break;

for (j = 0; j < geometry.geometries.length; j++) {
if (callback(
geometry.geometries[j],
featureIndex,
featureProperties,
featureBBox,
featureId
) === false)
if (
// @ts-expect-error: Known type conflict
callback(
geometry.geometries[j],
featureIndex,
featureProperties,
featureBBox,
featureId
) === false
)
return false;

@@ -247,2 +303,3 @@ }

previousValue = callback(
// @ts-expect-error: Known type conflict
previousValue,

@@ -267,7 +324,10 @@ currentGeometry,

case "Polygon":
if (callback(
_helpers.feature.call(void 0, geometry, properties, { bbox, id }),
featureIndex,
0
) === false)
if (
// @ts-expect-error: Known type conflict
callback(
_helpers.feature.call(void 0, geometry, properties, { bbox, id }),
featureIndex,
0
) === false
)
return false;

@@ -288,3 +348,8 @@ return;

}
for (var multiFeatureIndex = 0; multiFeatureIndex < geometry.coordinates.length; multiFeatureIndex++) {
for (
var multiFeatureIndex = 0;
// @ts-expect-error: Known type conflict
multiFeatureIndex < geometry.coordinates.length;
multiFeatureIndex++
) {
var coordinate = geometry.coordinates[multiFeatureIndex];

@@ -295,3 +360,6 @@ var geom = {

};
if (callback(_helpers.feature.call(void 0, geom, properties), featureIndex, multiFeatureIndex) === false)
if (
// @ts-expect-error: Known type conflict
callback(_helpers.feature.call(void 0, geom, properties), featureIndex, multiFeatureIndex) === false
)
return false;

@@ -310,2 +378,3 @@ }

previousValue = callback(
// @ts-expect-error: Known type conflict
previousValue,

@@ -330,29 +399,40 @@ currentFeature,

var prevGeomIndex = 0;
if (coordEach(
feature2,
function(currentCoord, coordIndex, featureIndexCoord, multiPartIndexCoord, geometryIndex) {
if (previousCoords === void 0 || featureIndex > previousFeatureIndex || multiPartIndexCoord > previousMultiIndex || geometryIndex > prevGeomIndex) {
if (
// @ts-expect-error: Known type conflict
coordEach(
feature2,
function(currentCoord, coordIndex, featureIndexCoord, multiPartIndexCoord, geometryIndex) {
if (
// @ts-expect-error: Known type conflict
previousCoords === void 0 || featureIndex > previousFeatureIndex || multiPartIndexCoord > previousMultiIndex || geometryIndex > prevGeomIndex
) {
previousCoords = currentCoord;
previousFeatureIndex = featureIndex;
previousMultiIndex = multiPartIndexCoord;
prevGeomIndex = geometryIndex;
segmentIndex = 0;
return;
}
var currentSegment = _helpers.lineString.call(void 0,
// @ts-expect-error: Known type conflict
[previousCoords, currentCoord],
feature2.properties
);
if (
// @ts-expect-error: Known type conflict
callback(
// @ts-expect-error: Known type conflict
currentSegment,
featureIndex,
multiFeatureIndex,
geometryIndex,
segmentIndex
) === false
)
return false;
segmentIndex++;
previousCoords = currentCoord;
previousFeatureIndex = featureIndex;
previousMultiIndex = multiPartIndexCoord;
prevGeomIndex = geometryIndex;
segmentIndex = 0;
return;
}
var currentSegment = _helpers.lineString.call(void 0,
[previousCoords, currentCoord],
feature2.properties
);
if (callback(
currentSegment,
featureIndex,
multiFeatureIndex,
geometryIndex,
segmentIndex
) === false)
return false;
segmentIndex++;
previousCoords = currentCoord;
}
) === false)
) === false
)
return false;

@@ -372,2 +452,3 @@ });

previousValue,
// @ts-expect-error: Known type conflict
currentSegment,

@@ -397,8 +478,12 @@ featureIndex,

for (var geometryIndex = 0; geometryIndex < coords.length; geometryIndex++) {
if (callback(
_helpers.lineString.call(void 0, coords[geometryIndex], feature2.properties),
featureIndex,
multiFeatureIndex,
geometryIndex
) === false)
if (
// @ts-expect-error: Known type conflict
callback(
// @ts-expect-error: Known type conflict
_helpers.lineString.call(void 0, coords[geometryIndex], feature2.properties),
featureIndex,
multiFeatureIndex,
geometryIndex
) === false
)
return false;

@@ -470,2 +555,3 @@ }

return _helpers.lineString.call(void 0,
// @ts-expect-error: Known type conflict
[coords[segmentIndex], coords[segmentIndex + 1]],

@@ -481,3 +567,5 @@ properties,

[
// @ts-expect-error: Known type conflict
coords[geometryIndex][segmentIndex],
// @ts-expect-error: Known type conflict
coords[geometryIndex][segmentIndex + 1]

@@ -495,3 +583,5 @@ ],

[
// @ts-expect-error: Known type conflict
coords[multiFeatureIndex][segmentIndex],
// @ts-expect-error: Known type conflict
coords[multiFeatureIndex][segmentIndex + 1]

@@ -508,6 +598,9 @@ ],

if (segmentIndex < 0)
segmentIndex = coords[multiFeatureIndex][geometryIndex].length - segmentIndex - 1;
segmentIndex = // @ts-expect-error: Known type conflict
coords[multiFeatureIndex][geometryIndex].length - segmentIndex - 1;
return _helpers.lineString.call(void 0,
[
// @ts-expect-error: Known type conflict
coords[multiFeatureIndex][geometryIndex][segmentIndex],
// @ts-expect-error: Known type conflict
coords[multiFeatureIndex][geometryIndex][segmentIndex + 1]

@@ -514,0 +607,0 @@ ],

@@ -5,273 +5,607 @@ import { GeoJsonProperties, Feature, FeatureCollection, GeometryCollection, Geometry, GeometryObject, BBox, LineString, MultiLineString, Polygon, MultiPolygon, Point } from 'geojson';

/**
* http://turfjs.org/docs/#coordreduce
* Callback for coordEach
*
* @callback coordEachCallback
* @param {number[]} currentCoord The current coordinate being processed.
* @param {number} coordIndex The current index of the coordinate being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
* @param {number} geometryIndex The current index of the Geometry being processed.
* @returns {void}
*/
declare function coordReduce<Reducer>(
geojson: AllGeoJSON,
callback: (
previousValue: Reducer,
currentCoord: number[],
coordIndex: number,
featureIndex: number,
multiFeatureIndex: number,
geometryIndex: number
) => Reducer,
initialValue?: Reducer
): Reducer;
/**
* http://turfjs.org/docs/#coordeach
* Iterate over coordinates in any GeoJSON object, similar to Array.forEach()
*
* @function
* @param {AllGeoJSON} geojson any GeoJSON object
* @param {coordEachCallback} callback a method that takes (currentCoord, coordIndex, featureIndex, multiFeatureIndex)
* @param {boolean} [excludeWrapCoord=false] whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration.
* @returns {void}
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {"foo": "bar"}),
* turf.point([36, 53], {"hello": "world"})
* ]);
*
* turf.coordEach(features, function (currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) {
* //=currentCoord
* //=coordIndex
* //=featureIndex
* //=multiFeatureIndex
* //=geometryIndex
* });
*/
declare function coordEach(
geojson: AllGeoJSON,
callback: (
currentCoord: number[],
coordIndex: number,
featureIndex: number,
multiFeatureIndex: number,
geometryIndex: number
) => void,
excludeWrapCoord?: boolean
): void;
declare function coordEach(geojson: AllGeoJSON, callback: (currentCoord: number[], coordIndex: number, featureIndex: number, multiFeatureIndex: number, geometryIndex: number) => void, excludeWrapCoord?: boolean): void;
/**
* http://turfjs.org/docs/#propeach
* Callback for coordReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback coordReduceCallback
* @param {Reducer} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {number[]} currentCoord The current coordinate being processed.
* @param {number} coordIndex The current index of the coordinate being processed.
* Starts at index 0, if an initialValue is provided, and at index 1 otherwise.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
* @param {number} geometryIndex The current index of the Geometry being processed.
* @returns {Reducer}
*/
declare function propEach<Props extends GeoJsonProperties>(
geojson: Feature<any> | FeatureCollection<any> | Feature<GeometryCollection>,
callback: (currentProperties: Props, featureIndex: number) => void
): void;
/**
* http://turfjs.org/docs/#propreduce
* Reduce coordinates in any GeoJSON object, similar to Array.reduce()
*
* @function
* @param {AllGeoJSON} geojson any GeoJSON object
* @param {coordReduceCallback} callback a method that takes (previousValue, currentCoord, coordIndex)
* @param {Reducer} [initialValue] Value to use as the first argument to the first call of the callback.
* @param {boolean} [excludeWrapCoord=false] whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration.
* @returns {Reducer} The value that results from the reduction.
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {"foo": "bar"}),
* turf.point([36, 53], {"hello": "world"})
* ]);
*
* turf.coordReduce(features, function (previousValue, currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) {
* //=previousValue
* //=currentCoord
* //=coordIndex
* //=featureIndex
* //=multiFeatureIndex
* //=geometryIndex
* return currentCoord;
* });
*/
declare function propReduce<
Reducer,
P extends GeoJsonProperties = GeoJsonProperties,
>(
geojson: Feature<any, P> | FeatureCollection<any, P> | Geometry,
callback: (
previousValue: Reducer,
currentProperties: P,
featureIndex: number
) => Reducer,
initialValue?: Reducer
): Reducer;
declare function coordReduce<Reducer>(geojson: AllGeoJSON, callback: (previousValue: Reducer, currentCoord: number[], coordIndex: number, featureIndex: number, multiFeatureIndex: number, geometryIndex: number) => Reducer, initialValue?: Reducer, excludeWrapCoord?: boolean): Reducer;
/**
* http://turfjs.org/docs/#featurereduce
* Callback for propEach
*
* @callback propEachCallback
* @param {GeoJsonProperties} currentProperties The current Properties being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @returns {void}
*/
declare function featureReduce<
Reducer,
G extends GeometryObject,
P extends GeoJsonProperties = GeoJsonProperties,
>(
geojson:
| Feature<G, P>
| FeatureCollection<G, P>
| Feature<GeometryCollection, P>,
callback: (
previousValue: Reducer,
currentFeature: Feature<G, P>,
featureIndex: number
) => Reducer,
initialValue?: Reducer
): Reducer;
/**
* http://turfjs.org/docs/#featureeach
* Iterate over properties in any GeoJSON object, similar to Array.forEach()
*
* @function
* @param {FeatureCollection|Feature} geojson any GeoJSON object
* @param {propEachCallback} callback a method that takes (currentProperties, featureIndex)
* @returns {void}
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* turf.propEach(features, function (currentProperties, featureIndex) {
* //=currentProperties
* //=featureIndex
* });
*/
declare function featureEach<
G extends GeometryObject,
P extends GeoJsonProperties = GeoJsonProperties,
>(
geojson:
| Feature<G, P>
| FeatureCollection<G, P>
| Feature<GeometryCollection, P>,
callback: (currentFeature: Feature<G, P>, featureIndex: number) => void
): void;
declare function propEach<Props extends GeoJsonProperties>(geojson: Feature<any> | FeatureCollection<any> | Feature<GeometryCollection>, callback: (currentProperties: Props, featureIndex: number) => void): void;
/**
* http://turfjs.org/docs/#coordall
* Callback for propReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback propReduceCallback
* @param {Reducer} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {GeoJsonProperties} currentProperties The current Properties being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @returns {Reducer}
*/
/**
* Reduce properties in any GeoJSON object into a single value,
* similar to how Array.reduce works. However, in this case we lazily run
* the reduction, so an array of all properties is unnecessary.
*
* @function
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
* @param {propReduceCallback} callback a method that takes (previousValue, currentProperties, featureIndex)
* @param {Reducer} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {Reducer} The value that results from the reduction.
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* turf.propReduce(features, function (previousValue, currentProperties, featureIndex) {
* //=previousValue
* //=currentProperties
* //=featureIndex
* return currentProperties
* });
*/
declare function propReduce<Reducer, P extends GeoJsonProperties = GeoJsonProperties>(geojson: Feature<any, P> | FeatureCollection<any, P> | Geometry, callback: (previousValue: Reducer, currentProperties: P, featureIndex: number) => Reducer, initialValue?: Reducer): Reducer;
/**
* Callback for featureEach
*
* @callback featureEachCallback
* @param {Feature<any>} currentFeature The current Feature being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @returns {void}
*/
/**
* Iterate over features in any GeoJSON object, similar to
* Array.forEach.
*
* @function
* @param {FeatureCollection|Feature|Feature<GeometryCollection>} geojson any GeoJSON object
* @param {featureEachCallback} callback a method that takes (currentFeature, featureIndex)
* @returns {void}
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* turf.featureEach(features, function (currentFeature, featureIndex) {
* //=currentFeature
* //=featureIndex
* });
*/
declare function featureEach<G extends GeometryObject, P extends GeoJsonProperties = GeoJsonProperties>(geojson: Feature<G, P> | FeatureCollection<G, P> | Feature<GeometryCollection, P>, callback: (currentFeature: Feature<G, P>, featureIndex: number) => void): void;
/**
* Callback for featureReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback featureReduceCallback
* @param {Reducer} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {Feature} currentFeature The current Feature being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @returns {Reducer}
*/
/**
* Reduce features in any GeoJSON object, similar to Array.reduce().
*
* @function
* @param {FeatureCollection|Feature|Feature<GeometryCollection>} geojson any GeoJSON object
* @param {featureReduceCallback} callback a method that takes (previousValue, currentFeature, featureIndex)
* @param {Reducer} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {Reducer} The value that results from the reduction.
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {"foo": "bar"}),
* turf.point([36, 53], {"hello": "world"})
* ]);
*
* turf.featureReduce(features, function (previousValue, currentFeature, featureIndex) {
* //=previousValue
* //=currentFeature
* //=featureIndex
* return currentFeature
* });
*/
declare function featureReduce<Reducer, G extends GeometryObject, P extends GeoJsonProperties = GeoJsonProperties>(geojson: Feature<G, P> | FeatureCollection<G, P> | Feature<GeometryCollection, P>, callback: (previousValue: Reducer, currentFeature: Feature<G, P>, featureIndex: number) => Reducer, initialValue?: Reducer): Reducer;
/**
* Get all coordinates from any GeoJSON object.
*
* @function
* @param {AllGeoJSON} geojson any GeoJSON object
* @returns {Array<Array<number>>} coordinate position array
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* var coords = turf.coordAll(features);
* //= [[26, 37], [36, 53]]
*/
declare function coordAll(geojson: AllGeoJSON): number[][];
/**
* http://turfjs.org/docs/#geomreduce
* Callback for geomEach
*
* @callback geomEachCallback
* @param {GeometryObject} currentGeometry The current Geometry being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {GeoJsonProperties} featureProperties The current Feature Properties being processed.
* @param {BBox} featureBBox The current Feature BBox being processed.
* @param {Id} featureId The current Feature Id being processed.
* @returns {void}
*/
declare function geomReduce<
Reducer,
G extends GeometryObject,
P extends GeoJsonProperties = GeoJsonProperties,
>(
geojson:
| Feature<G, P>
| FeatureCollection<G, P>
| G
| GeometryCollection
| Feature<GeometryCollection, P>,
callback: (
previousValue: Reducer,
currentGeometry: G,
featureIndex: number,
featureProperties: P,
featureBBox: BBox,
featureId: Id
) => Reducer,
initialValue?: Reducer
): Reducer;
/**
* http://turfjs.org/docs/#geomeach
* Iterate over each geometry in any GeoJSON object, similar to Array.forEach()
*
* @function
* @param {FeatureCollection|Feature|Geometry|GeometryObject|Feature<GeometryCollection>} geojson any GeoJSON object
* @param {geomEachCallback} callback a method that takes (currentGeometry, featureIndex, featureProperties, featureBBox, featureId)
* @returns {void}
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* turf.geomEach(features, function (currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {
* //=currentGeometry
* //=featureIndex
* //=featureProperties
* //=featureBBox
* //=featureId
* });
*/
declare function geomEach<
G extends GeometryObject | null,
P extends GeoJsonProperties = GeoJsonProperties,
>(
geojson:
| Feature<G, P>
| FeatureCollection<G, P>
| G
| GeometryCollection
| Feature<GeometryCollection, P>,
callback: (
currentGeometry: G,
featureIndex: number,
featureProperties: P,
featureBBox: BBox,
featureId: Id
) => void
): void;
declare function geomEach<G extends GeometryObject | null, P extends GeoJsonProperties = GeoJsonProperties>(geojson: Feature<G, P> | FeatureCollection<G, P> | G | GeometryCollection | Feature<GeometryCollection, P>, callback: (currentGeometry: G, featureIndex: number, featureProperties: P, featureBBox: BBox, featureId: Id) => void): void;
/**
* http://turfjs.org/docs/#flattenreduce
* Callback for geomReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback geomReduceCallback
* @param {Reducer} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {GeometryObject} currentGeometry The current Geometry being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {GeoJsonProperties} featureProperties The current Feature Properties being processed.
* @param {BBox} featureBBox The current Feature BBox being processed.
* @param {Id} featureId The current Feature Id being processed.
* @returns {Reducer}
*/
declare function flattenReduce<
Reducer,
G extends GeometryObject,
P extends GeoJsonProperties = GeoJsonProperties,
>(
geojson:
| Feature<G, P>
| FeatureCollection<G, P>
| G
| GeometryCollection
| Feature<GeometryCollection, P>,
callback: (
previousValue: Reducer,
currentFeature: Feature<G, P>,
featureIndex: number,
multiFeatureIndex: number
) => Reducer,
initialValue?: Reducer
): Reducer;
/**
* http://turfjs.org/docs/#flatteneach
* Reduce geometry in any GeoJSON object, similar to Array.reduce().
*
* @function
* @param {FeatureCollection|Feature|GeometryObject|GeometryCollection|Feature<GeometryCollection>} geojson any GeoJSON object
* @param {geomReduceCallback} callback a method that takes (previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId)
* @param {Reducer} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {Reducer} The value that results from the reduction.
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* turf.geomReduce(features, function (previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {
* //=previousValue
* //=currentGeometry
* //=featureIndex
* //=featureProperties
* //=featureBBox
* //=featureId
* return currentGeometry
* });
*/
declare function flattenEach<
G extends GeometryObject = GeometryObject,
P extends GeoJsonProperties = GeoJsonProperties,
>(
geojson:
| Feature<G, P>
| FeatureCollection<G, P>
| G
| GeometryCollection
| Feature<GeometryCollection, P>,
callback: (
currentFeature: Feature<G, P>,
featureIndex: number,
multiFeatureIndex: number
) => void
): void;
declare function geomReduce<Reducer, G extends GeometryObject, P extends GeoJsonProperties = GeoJsonProperties>(geojson: Feature<G, P> | FeatureCollection<G, P> | G | GeometryCollection | Feature<GeometryCollection, P>, callback: (previousValue: Reducer, currentGeometry: G, featureIndex: number, featureProperties: P, featureBBox: BBox, featureId: Id) => Reducer, initialValue?: Reducer): Reducer;
/**
* http://turfjs.org/docs/#segmentreduce
* Callback for flattenEach
*
* @callback flattenEachCallback
* @param {Feature} currentFeature The current flattened feature being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
* @returns {void}
*/
declare function segmentReduce<
Reducer,
P extends GeoJsonProperties = GeoJsonProperties,
>(
geojson:
| FeatureCollection<Lines, P>
| Feature<Lines, P>
| Lines
| Feature<GeometryCollection, P>
| GeometryCollection,
callback: (
previousValue?: Reducer,
currentSegment?: Feature<LineString, P>,
featureIndex?: number,
multiFeatureIndex?: number,
segmentIndex?: number,
geometryIndex?: number
) => Reducer,
initialValue?: Reducer
): Reducer;
/**
* http://turfjs.org/docs/#segmenteach
* Iterate over flattened features in any GeoJSON object, similar to
* Array.forEach.
*
* @function
* @param {FeatureCollection|Feature|GeometryObject|GeometryCollection|Feature<GeometryCollection>} geojson any GeoJSON object
* @param {flattenEachCallback} callback a method that takes (currentFeature, featureIndex, multiFeatureIndex)
* @returns {void}
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.multiPoint([[40, 30], [36, 53]], {hello: 'world'})
* ]);
*
* turf.flattenEach(features, function (currentFeature, featureIndex, multiFeatureIndex) {
* //=currentFeature
* //=featureIndex
* //=multiFeatureIndex
* });
*/
declare function segmentEach<P extends GeoJsonProperties = GeoJsonProperties>(
geojson: AllGeoJSON,
callback: (
currentSegment?: Feature<LineString, P>,
featureIndex?: number,
multiFeatureIndex?: number,
segmentIndex?: number,
geometryIndex?: number
) => void
): void;
declare function flattenEach<G extends GeometryObject = GeometryObject, P extends GeoJsonProperties = GeoJsonProperties>(geojson: Feature<G, P> | FeatureCollection<G, P> | G | GeometryCollection | Feature<GeometryCollection, P>, callback: (currentFeature: Feature<G, P>, featureIndex: number, multiFeatureIndex: number) => void): void;
/**
* http://turfjs.org/docs/#linereduce
* Callback for flattenReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback flattenReduceCallback
* @param {Reducer} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {Feature} currentFeature The current Feature being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
* @returns {Reducer}
*/
declare function lineReduce<
Reducer,
P extends GeoJsonProperties = GeoJsonProperties,
>(
geojson:
| FeatureCollection<Lines, P>
| Feature<Lines, P>
| Lines
| Feature<GeometryCollection, P>
| GeometryCollection,
callback: (
previousValue?: Reducer,
currentLine?: Feature<LineString, P>,
featureIndex?: number,
multiFeatureIndex?: number,
geometryIndex?: number
) => Reducer,
initialValue?: Reducer
): Reducer;
/**
* http://turfjs.org/docs/#lineeach
* Reduce flattened features in any GeoJSON object, similar to Array.reduce().
*
* @function
* @param {FeatureCollection|Feature|GeometryObject|GeometryCollection|Feature<GeometryCollection>} geojson any GeoJSON object
* @param {flattenReduceCallback} callback a method that takes (previousValue, currentFeature, featureIndex, multiFeatureIndex)
* @param {Reducer} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {Reducer} The value that results from the reduction.
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.multiPoint([[40, 30], [36, 53]], {hello: 'world'})
* ]);
*
* turf.flattenReduce(features, function (previousValue, currentFeature, featureIndex, multiFeatureIndex) {
* //=previousValue
* //=currentFeature
* //=featureIndex
* //=multiFeatureIndex
* return currentFeature
* });
*/
declare function lineEach<P extends GeoJsonProperties = GeoJsonProperties>(
geojson:
| FeatureCollection<Lines, P>
| Feature<Lines, P>
| Lines
| Feature<GeometryCollection, P>
| GeometryCollection,
callback: (
currentLine: Feature<LineString, P>,
featureIndex?: number,
multiFeatureIndex?: number,
geometryIndex?: number
) => void
): void;
declare function flattenReduce<Reducer, G extends GeometryObject, P extends GeoJsonProperties = GeoJsonProperties>(geojson: Feature<G, P> | FeatureCollection<G, P> | G | GeometryCollection | Feature<GeometryCollection, P>, callback: (previousValue: Reducer, currentFeature: Feature<G, P>, featureIndex: number, multiFeatureIndex: number) => Reducer, initialValue?: Reducer): Reducer;
/**
* http://turfjs.org/docs/#findsegment
* Callback for segmentEach
*
* @callback segmentEachCallback
* @param {Feature<LineString>} currentSegment The current Segment being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
* @param {number} geometryIndex The current index of the Geometry being processed.
* @param {number} segmentIndex The current index of the Segment being processed.
* @returns {void}
*/
declare function findSegment<
G extends LineString | MultiLineString | Polygon | MultiPolygon,
P extends GeoJsonProperties = GeoJsonProperties,
>(
geojson: Feature<G, P> | FeatureCollection<G, P> | G,
options?: {
/**
* Iterate over 2-vertex line segment in any GeoJSON object, similar to Array.forEach()
* (Multi)Point geometries do not contain segments therefore they are ignored during this operation.
*
* @param {AllGeoJSON} geojson any GeoJSON
* @param {segmentEachCallback} callback a method that takes (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex)
* @returns {void}
* @example
* var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
*
* // Iterate over GeoJSON by 2-vertex segments
* turf.segmentEach(polygon, function (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) {
* //=currentSegment
* //=featureIndex
* //=multiFeatureIndex
* //=geometryIndex
* //=segmentIndex
* });
*
* // Calculate the total number of segments
* var total = 0;
* turf.segmentEach(polygon, function () {
* total++;
* });
*/
declare function segmentEach<P extends GeoJsonProperties = GeoJsonProperties>(geojson: AllGeoJSON, callback: (currentSegment?: Feature<LineString, P>, featureIndex?: number, multiFeatureIndex?: number, segmentIndex?: number, geometryIndex?: number) => void): void;
/**
* Callback for segmentReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback segmentReduceCallback
* @param {Reducer} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {Feature<LineString>} currentSegment The current Segment being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
* @param {number} geometryIndex The current index of the Geometry being processed.
* @param {number} segmentIndex The current index of the Segment being processed.
* @returns {Reducer}
*/
/**
* Reduce 2-vertex line segment in any GeoJSON object, similar to Array.reduce()
* (Multi)Point geometries do not contain segments therefore they are ignored during this operation.
*
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON
* @param {segmentReduceCallback} callback a method that takes (previousValue, currentSegment, currentIndex)
* @param {Reducer} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {Reducer}
* @example
* var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
*
* // Iterate over GeoJSON by 2-vertex segments
* turf.segmentReduce(polygon, function (previousSegment, currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) {
* //= previousSegment
* //= currentSegment
* //= featureIndex
* //= multiFeatureIndex
* //= geometryIndex
* //= segmentIndex
* return currentSegment
* });
*
* // Calculate the total number of segments
* var initialValue = 0
* var total = turf.segmentReduce(polygon, function (previousValue) {
* previousValue++;
* return previousValue;
* }, initialValue);
*/
declare function segmentReduce<Reducer, P extends GeoJsonProperties = GeoJsonProperties>(geojson: FeatureCollection<Lines, P> | Feature<Lines, P> | Lines | Feature<GeometryCollection, P> | GeometryCollection, callback: (previousValue?: Reducer, currentSegment?: Feature<LineString, P>, featureIndex?: number, multiFeatureIndex?: number, segmentIndex?: number, geometryIndex?: number) => Reducer, initialValue?: Reducer): Reducer;
/**
* Callback for lineEach
*
* @callback lineEachCallback
* @param {Feature<LineString>} currentLine The current LineString|LinearRing being processed
* @param {number} featureIndex The current index of the Feature being processed
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed
* @param {number} geometryIndex The current index of the Geometry being processed
* @returns {void}
*/
/**
* Iterate over line or ring coordinates in LineString, Polygon, MultiLineString, MultiPolygon Features or Geometries,
* similar to Array.forEach.
*
* @function
* @param {FeatureCollection<Lines>|Feature<Lines>|Lines|Feature<GeometryCollection>|GeometryCollection} geojson object
* @param {lineEachCallback} callback a method that takes (currentLine, featureIndex, multiFeatureIndex, geometryIndex)
* @returns {void}
* @example
* var multiLine = turf.multiLineString([
* [[26, 37], [35, 45]],
* [[36, 53], [38, 50], [41, 55]]
* ]);
*
* turf.lineEach(multiLine, function (currentLine, featureIndex, multiFeatureIndex, geometryIndex) {
* //=currentLine
* //=featureIndex
* //=multiFeatureIndex
* //=geometryIndex
* });
*/
declare function lineEach<P extends GeoJsonProperties = GeoJsonProperties>(geojson: FeatureCollection<Lines, P> | Feature<Lines, P> | Lines | Feature<GeometryCollection, P> | GeometryCollection, callback: (currentLine: Feature<LineString, P>, featureIndex?: number, multiFeatureIndex?: number, geometryIndex?: number) => void): void;
/**
* Callback for lineReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback lineReduceCallback
* @param {Reducer} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {Feature<LineString>} currentLine The current LineString|LinearRing being processed.
* @param {number} featureIndex The current index of the Feature being processed
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed
* @param {number} geometryIndex The current index of the Geometry being processed
* @returns {Reducer}
*/
/**
* Reduce features in any GeoJSON object, similar to Array.reduce().
*
* @function
* @param {FeatureCollection<Lines>|Feature<Lines>|Lines|Feature<GeometryCollection>|GeometryCollection} geojson object
* @param {Function} callback a method that takes (previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex)
* @param {Reducer} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {Reducer} The value that results from the reduction.
* @example
* var multiPoly = turf.multiPolygon([
* turf.polygon([[[12,48],[2,41],[24,38],[12,48]], [[9,44],[13,41],[13,45],[9,44]]]),
* turf.polygon([[[5, 5], [0, 0], [2, 2], [4, 4], [5, 5]]])
* ]);
*
* turf.lineReduce(multiPoly, function (previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex) {
* //=previousValue
* //=currentLine
* //=featureIndex
* //=multiFeatureIndex
* //=geometryIndex
* return currentLine
* });
*/
declare function lineReduce<Reducer, P extends GeoJsonProperties = GeoJsonProperties>(geojson: FeatureCollection<Lines, P> | Feature<Lines, P> | Lines | Feature<GeometryCollection, P> | GeometryCollection, callback: (previousValue?: Reducer, currentLine?: Feature<LineString, P>, featureIndex?: number, multiFeatureIndex?: number, geometryIndex?: number) => Reducer, initialValue?: Reducer): Reducer;
/**
* Finds a particular 2-vertex LineString Segment from a GeoJSON using `@turf/meta` indexes.
*
* Negative indexes are permitted.
* Point & MultiPoint will always return null.
*
* @param {FeatureCollection|Feature|Geometry} geojson Any GeoJSON Feature or Geometry
* @param {Object} [options={}] Optional parameters
* @param {number} [options.featureIndex=0] Feature Index
* @param {number} [options.multiFeatureIndex=0] Multi-Feature Index
* @param {number} [options.geometryIndex=0] Geometry Index
* @param {number} [options.segmentIndex=0] Segment Index
* @param {Object} [options.properties={}] Translate Properties to output LineString
* @param {BBox} [options.bbox={}] Translate BBox to output LineString
* @param {number|string} [options.id={}] Translate Id to output LineString
* @returns {Feature<LineString>} 2-vertex GeoJSON Feature LineString
* @example
* var multiLine = turf.multiLineString([
* [[10, 10], [50, 30], [30, 40]],
* [[-10, -10], [-50, -30], [-30, -40]]
* ]);
*
* // First Segment (defaults are 0)
* turf.findSegment(multiLine);
* // => Feature<LineString<[[10, 10], [50, 30]]>>
*
* // First Segment of 2nd Multi Feature
* turf.findSegment(multiLine, {multiFeatureIndex: 1});
* // => Feature<LineString<[[-10, -10], [-50, -30]]>>
*
* // Last Segment of Last Multi Feature
* turf.findSegment(multiLine, {multiFeatureIndex: -1, segmentIndex: -1});
* // => Feature<LineString<[[-50, -30], [-30, -40]]>>
*/
declare function findSegment<G extends LineString | MultiLineString | Polygon | MultiPolygon, P extends GeoJsonProperties = GeoJsonProperties>(geojson: Feature<G, P> | FeatureCollection<G, P> | G, options?: {
featureIndex?: number;

@@ -284,14 +618,37 @@ multiFeatureIndex?: number;

id?: Id;
}
): Feature<LineString, P>;
}): Feature<LineString, P>;
/**
* http://turfjs.org/docs/#findpoint
* Finds a particular Point from a GeoJSON using `@turf/meta` indexes.
*
* Negative indexes are permitted.
*
* @param {FeatureCollection|Feature|Geometry} geojson Any GeoJSON Feature or Geometry
* @param {Object} [options={}] Optional parameters
* @param {number} [options.featureIndex=0] Feature Index
* @param {number} [options.multiFeatureIndex=0] Multi-Feature Index
* @param {number} [options.geometryIndex=0] Geometry Index
* @param {number} [options.coordIndex=0] Coord Index
* @param {Object} [options.properties={}] Translate Properties to output Point
* @param {BBox} [options.bbox={}] Translate BBox to output Point
* @param {number|string} [options.id={}] Translate Id to output Point
* @returns {Feature<Point>} 2-vertex GeoJSON Feature Point
* @example
* var multiLine = turf.multiLineString([
* [[10, 10], [50, 30], [30, 40]],
* [[-10, -10], [-50, -30], [-30, -40]]
* ]);
*
* // First Segment (defaults are 0)
* turf.findPoint(multiLine);
* // => Feature<Point<[10, 10]>>
*
* // First Segment of the 2nd Multi-Feature
* turf.findPoint(multiLine, {multiFeatureIndex: 1});
* // => Feature<Point<[-10, -10]>>
*
* // Last Segment of last Multi-Feature
* turf.findPoint(multiLine, {multiFeatureIndex: -1, coordIndex: -1});
* // => Feature<Point<[-30, -40]>>
*/
declare function findPoint<
G extends GeometryObject,
P extends GeoJsonProperties = GeoJsonProperties,
>(
geojson: Feature<G, P> | FeatureCollection<G, P> | G,
options?: {
declare function findPoint<G extends GeometryObject, P extends GeoJsonProperties = GeoJsonProperties>(geojson: Feature<G, P> | FeatureCollection<G, P> | G, options?: {
featureIndex?: number;

@@ -304,5 +661,4 @@ multiFeatureIndex?: number;

id?: Id;
}
): Feature<Point, P>;
}): Feature<Point, P>;
export { coordAll, coordEach, coordReduce, featureEach, featureReduce, findPoint, findSegment, flattenEach, flattenReduce, geomEach, geomReduce, lineEach, lineReduce, propEach, propReduce, segmentEach, segmentReduce };

@@ -5,273 +5,607 @@ import { GeoJsonProperties, Feature, FeatureCollection, GeometryCollection, Geometry, GeometryObject, BBox, LineString, MultiLineString, Polygon, MultiPolygon, Point } from 'geojson';

/**
* http://turfjs.org/docs/#coordreduce
* Callback for coordEach
*
* @callback coordEachCallback
* @param {number[]} currentCoord The current coordinate being processed.
* @param {number} coordIndex The current index of the coordinate being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
* @param {number} geometryIndex The current index of the Geometry being processed.
* @returns {void}
*/
declare function coordReduce<Reducer>(
geojson: AllGeoJSON,
callback: (
previousValue: Reducer,
currentCoord: number[],
coordIndex: number,
featureIndex: number,
multiFeatureIndex: number,
geometryIndex: number
) => Reducer,
initialValue?: Reducer
): Reducer;
/**
* http://turfjs.org/docs/#coordeach
* Iterate over coordinates in any GeoJSON object, similar to Array.forEach()
*
* @function
* @param {AllGeoJSON} geojson any GeoJSON object
* @param {coordEachCallback} callback a method that takes (currentCoord, coordIndex, featureIndex, multiFeatureIndex)
* @param {boolean} [excludeWrapCoord=false] whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration.
* @returns {void}
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {"foo": "bar"}),
* turf.point([36, 53], {"hello": "world"})
* ]);
*
* turf.coordEach(features, function (currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) {
* //=currentCoord
* //=coordIndex
* //=featureIndex
* //=multiFeatureIndex
* //=geometryIndex
* });
*/
declare function coordEach(
geojson: AllGeoJSON,
callback: (
currentCoord: number[],
coordIndex: number,
featureIndex: number,
multiFeatureIndex: number,
geometryIndex: number
) => void,
excludeWrapCoord?: boolean
): void;
declare function coordEach(geojson: AllGeoJSON, callback: (currentCoord: number[], coordIndex: number, featureIndex: number, multiFeatureIndex: number, geometryIndex: number) => void, excludeWrapCoord?: boolean): void;
/**
* http://turfjs.org/docs/#propeach
* Callback for coordReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback coordReduceCallback
* @param {Reducer} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {number[]} currentCoord The current coordinate being processed.
* @param {number} coordIndex The current index of the coordinate being processed.
* Starts at index 0, if an initialValue is provided, and at index 1 otherwise.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
* @param {number} geometryIndex The current index of the Geometry being processed.
* @returns {Reducer}
*/
declare function propEach<Props extends GeoJsonProperties>(
geojson: Feature<any> | FeatureCollection<any> | Feature<GeometryCollection>,
callback: (currentProperties: Props, featureIndex: number) => void
): void;
/**
* http://turfjs.org/docs/#propreduce
* Reduce coordinates in any GeoJSON object, similar to Array.reduce()
*
* @function
* @param {AllGeoJSON} geojson any GeoJSON object
* @param {coordReduceCallback} callback a method that takes (previousValue, currentCoord, coordIndex)
* @param {Reducer} [initialValue] Value to use as the first argument to the first call of the callback.
* @param {boolean} [excludeWrapCoord=false] whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration.
* @returns {Reducer} The value that results from the reduction.
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {"foo": "bar"}),
* turf.point([36, 53], {"hello": "world"})
* ]);
*
* turf.coordReduce(features, function (previousValue, currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) {
* //=previousValue
* //=currentCoord
* //=coordIndex
* //=featureIndex
* //=multiFeatureIndex
* //=geometryIndex
* return currentCoord;
* });
*/
declare function propReduce<
Reducer,
P extends GeoJsonProperties = GeoJsonProperties,
>(
geojson: Feature<any, P> | FeatureCollection<any, P> | Geometry,
callback: (
previousValue: Reducer,
currentProperties: P,
featureIndex: number
) => Reducer,
initialValue?: Reducer
): Reducer;
declare function coordReduce<Reducer>(geojson: AllGeoJSON, callback: (previousValue: Reducer, currentCoord: number[], coordIndex: number, featureIndex: number, multiFeatureIndex: number, geometryIndex: number) => Reducer, initialValue?: Reducer, excludeWrapCoord?: boolean): Reducer;
/**
* http://turfjs.org/docs/#featurereduce
* Callback for propEach
*
* @callback propEachCallback
* @param {GeoJsonProperties} currentProperties The current Properties being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @returns {void}
*/
declare function featureReduce<
Reducer,
G extends GeometryObject,
P extends GeoJsonProperties = GeoJsonProperties,
>(
geojson:
| Feature<G, P>
| FeatureCollection<G, P>
| Feature<GeometryCollection, P>,
callback: (
previousValue: Reducer,
currentFeature: Feature<G, P>,
featureIndex: number
) => Reducer,
initialValue?: Reducer
): Reducer;
/**
* http://turfjs.org/docs/#featureeach
* Iterate over properties in any GeoJSON object, similar to Array.forEach()
*
* @function
* @param {FeatureCollection|Feature} geojson any GeoJSON object
* @param {propEachCallback} callback a method that takes (currentProperties, featureIndex)
* @returns {void}
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* turf.propEach(features, function (currentProperties, featureIndex) {
* //=currentProperties
* //=featureIndex
* });
*/
declare function featureEach<
G extends GeometryObject,
P extends GeoJsonProperties = GeoJsonProperties,
>(
geojson:
| Feature<G, P>
| FeatureCollection<G, P>
| Feature<GeometryCollection, P>,
callback: (currentFeature: Feature<G, P>, featureIndex: number) => void
): void;
declare function propEach<Props extends GeoJsonProperties>(geojson: Feature<any> | FeatureCollection<any> | Feature<GeometryCollection>, callback: (currentProperties: Props, featureIndex: number) => void): void;
/**
* http://turfjs.org/docs/#coordall
* Callback for propReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback propReduceCallback
* @param {Reducer} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {GeoJsonProperties} currentProperties The current Properties being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @returns {Reducer}
*/
/**
* Reduce properties in any GeoJSON object into a single value,
* similar to how Array.reduce works. However, in this case we lazily run
* the reduction, so an array of all properties is unnecessary.
*
* @function
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
* @param {propReduceCallback} callback a method that takes (previousValue, currentProperties, featureIndex)
* @param {Reducer} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {Reducer} The value that results from the reduction.
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* turf.propReduce(features, function (previousValue, currentProperties, featureIndex) {
* //=previousValue
* //=currentProperties
* //=featureIndex
* return currentProperties
* });
*/
declare function propReduce<Reducer, P extends GeoJsonProperties = GeoJsonProperties>(geojson: Feature<any, P> | FeatureCollection<any, P> | Geometry, callback: (previousValue: Reducer, currentProperties: P, featureIndex: number) => Reducer, initialValue?: Reducer): Reducer;
/**
* Callback for featureEach
*
* @callback featureEachCallback
* @param {Feature<any>} currentFeature The current Feature being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @returns {void}
*/
/**
* Iterate over features in any GeoJSON object, similar to
* Array.forEach.
*
* @function
* @param {FeatureCollection|Feature|Feature<GeometryCollection>} geojson any GeoJSON object
* @param {featureEachCallback} callback a method that takes (currentFeature, featureIndex)
* @returns {void}
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* turf.featureEach(features, function (currentFeature, featureIndex) {
* //=currentFeature
* //=featureIndex
* });
*/
declare function featureEach<G extends GeometryObject, P extends GeoJsonProperties = GeoJsonProperties>(geojson: Feature<G, P> | FeatureCollection<G, P> | Feature<GeometryCollection, P>, callback: (currentFeature: Feature<G, P>, featureIndex: number) => void): void;
/**
* Callback for featureReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback featureReduceCallback
* @param {Reducer} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {Feature} currentFeature The current Feature being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @returns {Reducer}
*/
/**
* Reduce features in any GeoJSON object, similar to Array.reduce().
*
* @function
* @param {FeatureCollection|Feature|Feature<GeometryCollection>} geojson any GeoJSON object
* @param {featureReduceCallback} callback a method that takes (previousValue, currentFeature, featureIndex)
* @param {Reducer} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {Reducer} The value that results from the reduction.
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {"foo": "bar"}),
* turf.point([36, 53], {"hello": "world"})
* ]);
*
* turf.featureReduce(features, function (previousValue, currentFeature, featureIndex) {
* //=previousValue
* //=currentFeature
* //=featureIndex
* return currentFeature
* });
*/
declare function featureReduce<Reducer, G extends GeometryObject, P extends GeoJsonProperties = GeoJsonProperties>(geojson: Feature<G, P> | FeatureCollection<G, P> | Feature<GeometryCollection, P>, callback: (previousValue: Reducer, currentFeature: Feature<G, P>, featureIndex: number) => Reducer, initialValue?: Reducer): Reducer;
/**
* Get all coordinates from any GeoJSON object.
*
* @function
* @param {AllGeoJSON} geojson any GeoJSON object
* @returns {Array<Array<number>>} coordinate position array
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* var coords = turf.coordAll(features);
* //= [[26, 37], [36, 53]]
*/
declare function coordAll(geojson: AllGeoJSON): number[][];
/**
* http://turfjs.org/docs/#geomreduce
* Callback for geomEach
*
* @callback geomEachCallback
* @param {GeometryObject} currentGeometry The current Geometry being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {GeoJsonProperties} featureProperties The current Feature Properties being processed.
* @param {BBox} featureBBox The current Feature BBox being processed.
* @param {Id} featureId The current Feature Id being processed.
* @returns {void}
*/
declare function geomReduce<
Reducer,
G extends GeometryObject,
P extends GeoJsonProperties = GeoJsonProperties,
>(
geojson:
| Feature<G, P>
| FeatureCollection<G, P>
| G
| GeometryCollection
| Feature<GeometryCollection, P>,
callback: (
previousValue: Reducer,
currentGeometry: G,
featureIndex: number,
featureProperties: P,
featureBBox: BBox,
featureId: Id
) => Reducer,
initialValue?: Reducer
): Reducer;
/**
* http://turfjs.org/docs/#geomeach
* Iterate over each geometry in any GeoJSON object, similar to Array.forEach()
*
* @function
* @param {FeatureCollection|Feature|Geometry|GeometryObject|Feature<GeometryCollection>} geojson any GeoJSON object
* @param {geomEachCallback} callback a method that takes (currentGeometry, featureIndex, featureProperties, featureBBox, featureId)
* @returns {void}
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* turf.geomEach(features, function (currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {
* //=currentGeometry
* //=featureIndex
* //=featureProperties
* //=featureBBox
* //=featureId
* });
*/
declare function geomEach<
G extends GeometryObject | null,
P extends GeoJsonProperties = GeoJsonProperties,
>(
geojson:
| Feature<G, P>
| FeatureCollection<G, P>
| G
| GeometryCollection
| Feature<GeometryCollection, P>,
callback: (
currentGeometry: G,
featureIndex: number,
featureProperties: P,
featureBBox: BBox,
featureId: Id
) => void
): void;
declare function geomEach<G extends GeometryObject | null, P extends GeoJsonProperties = GeoJsonProperties>(geojson: Feature<G, P> | FeatureCollection<G, P> | G | GeometryCollection | Feature<GeometryCollection, P>, callback: (currentGeometry: G, featureIndex: number, featureProperties: P, featureBBox: BBox, featureId: Id) => void): void;
/**
* http://turfjs.org/docs/#flattenreduce
* Callback for geomReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback geomReduceCallback
* @param {Reducer} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {GeometryObject} currentGeometry The current Geometry being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {GeoJsonProperties} featureProperties The current Feature Properties being processed.
* @param {BBox} featureBBox The current Feature BBox being processed.
* @param {Id} featureId The current Feature Id being processed.
* @returns {Reducer}
*/
declare function flattenReduce<
Reducer,
G extends GeometryObject,
P extends GeoJsonProperties = GeoJsonProperties,
>(
geojson:
| Feature<G, P>
| FeatureCollection<G, P>
| G
| GeometryCollection
| Feature<GeometryCollection, P>,
callback: (
previousValue: Reducer,
currentFeature: Feature<G, P>,
featureIndex: number,
multiFeatureIndex: number
) => Reducer,
initialValue?: Reducer
): Reducer;
/**
* http://turfjs.org/docs/#flatteneach
* Reduce geometry in any GeoJSON object, similar to Array.reduce().
*
* @function
* @param {FeatureCollection|Feature|GeometryObject|GeometryCollection|Feature<GeometryCollection>} geojson any GeoJSON object
* @param {geomReduceCallback} callback a method that takes (previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId)
* @param {Reducer} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {Reducer} The value that results from the reduction.
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* turf.geomReduce(features, function (previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {
* //=previousValue
* //=currentGeometry
* //=featureIndex
* //=featureProperties
* //=featureBBox
* //=featureId
* return currentGeometry
* });
*/
declare function flattenEach<
G extends GeometryObject = GeometryObject,
P extends GeoJsonProperties = GeoJsonProperties,
>(
geojson:
| Feature<G, P>
| FeatureCollection<G, P>
| G
| GeometryCollection
| Feature<GeometryCollection, P>,
callback: (
currentFeature: Feature<G, P>,
featureIndex: number,
multiFeatureIndex: number
) => void
): void;
declare function geomReduce<Reducer, G extends GeometryObject, P extends GeoJsonProperties = GeoJsonProperties>(geojson: Feature<G, P> | FeatureCollection<G, P> | G | GeometryCollection | Feature<GeometryCollection, P>, callback: (previousValue: Reducer, currentGeometry: G, featureIndex: number, featureProperties: P, featureBBox: BBox, featureId: Id) => Reducer, initialValue?: Reducer): Reducer;
/**
* http://turfjs.org/docs/#segmentreduce
* Callback for flattenEach
*
* @callback flattenEachCallback
* @param {Feature} currentFeature The current flattened feature being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
* @returns {void}
*/
declare function segmentReduce<
Reducer,
P extends GeoJsonProperties = GeoJsonProperties,
>(
geojson:
| FeatureCollection<Lines, P>
| Feature<Lines, P>
| Lines
| Feature<GeometryCollection, P>
| GeometryCollection,
callback: (
previousValue?: Reducer,
currentSegment?: Feature<LineString, P>,
featureIndex?: number,
multiFeatureIndex?: number,
segmentIndex?: number,
geometryIndex?: number
) => Reducer,
initialValue?: Reducer
): Reducer;
/**
* http://turfjs.org/docs/#segmenteach
* Iterate over flattened features in any GeoJSON object, similar to
* Array.forEach.
*
* @function
* @param {FeatureCollection|Feature|GeometryObject|GeometryCollection|Feature<GeometryCollection>} geojson any GeoJSON object
* @param {flattenEachCallback} callback a method that takes (currentFeature, featureIndex, multiFeatureIndex)
* @returns {void}
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.multiPoint([[40, 30], [36, 53]], {hello: 'world'})
* ]);
*
* turf.flattenEach(features, function (currentFeature, featureIndex, multiFeatureIndex) {
* //=currentFeature
* //=featureIndex
* //=multiFeatureIndex
* });
*/
declare function segmentEach<P extends GeoJsonProperties = GeoJsonProperties>(
geojson: AllGeoJSON,
callback: (
currentSegment?: Feature<LineString, P>,
featureIndex?: number,
multiFeatureIndex?: number,
segmentIndex?: number,
geometryIndex?: number
) => void
): void;
declare function flattenEach<G extends GeometryObject = GeometryObject, P extends GeoJsonProperties = GeoJsonProperties>(geojson: Feature<G, P> | FeatureCollection<G, P> | G | GeometryCollection | Feature<GeometryCollection, P>, callback: (currentFeature: Feature<G, P>, featureIndex: number, multiFeatureIndex: number) => void): void;
/**
* http://turfjs.org/docs/#linereduce
* Callback for flattenReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback flattenReduceCallback
* @param {Reducer} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {Feature} currentFeature The current Feature being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
* @returns {Reducer}
*/
declare function lineReduce<
Reducer,
P extends GeoJsonProperties = GeoJsonProperties,
>(
geojson:
| FeatureCollection<Lines, P>
| Feature<Lines, P>
| Lines
| Feature<GeometryCollection, P>
| GeometryCollection,
callback: (
previousValue?: Reducer,
currentLine?: Feature<LineString, P>,
featureIndex?: number,
multiFeatureIndex?: number,
geometryIndex?: number
) => Reducer,
initialValue?: Reducer
): Reducer;
/**
* http://turfjs.org/docs/#lineeach
* Reduce flattened features in any GeoJSON object, similar to Array.reduce().
*
* @function
* @param {FeatureCollection|Feature|GeometryObject|GeometryCollection|Feature<GeometryCollection>} geojson any GeoJSON object
* @param {flattenReduceCallback} callback a method that takes (previousValue, currentFeature, featureIndex, multiFeatureIndex)
* @param {Reducer} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {Reducer} The value that results from the reduction.
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.multiPoint([[40, 30], [36, 53]], {hello: 'world'})
* ]);
*
* turf.flattenReduce(features, function (previousValue, currentFeature, featureIndex, multiFeatureIndex) {
* //=previousValue
* //=currentFeature
* //=featureIndex
* //=multiFeatureIndex
* return currentFeature
* });
*/
declare function lineEach<P extends GeoJsonProperties = GeoJsonProperties>(
geojson:
| FeatureCollection<Lines, P>
| Feature<Lines, P>
| Lines
| Feature<GeometryCollection, P>
| GeometryCollection,
callback: (
currentLine: Feature<LineString, P>,
featureIndex?: number,
multiFeatureIndex?: number,
geometryIndex?: number
) => void
): void;
declare function flattenReduce<Reducer, G extends GeometryObject, P extends GeoJsonProperties = GeoJsonProperties>(geojson: Feature<G, P> | FeatureCollection<G, P> | G | GeometryCollection | Feature<GeometryCollection, P>, callback: (previousValue: Reducer, currentFeature: Feature<G, P>, featureIndex: number, multiFeatureIndex: number) => Reducer, initialValue?: Reducer): Reducer;
/**
* http://turfjs.org/docs/#findsegment
* Callback for segmentEach
*
* @callback segmentEachCallback
* @param {Feature<LineString>} currentSegment The current Segment being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
* @param {number} geometryIndex The current index of the Geometry being processed.
* @param {number} segmentIndex The current index of the Segment being processed.
* @returns {void}
*/
declare function findSegment<
G extends LineString | MultiLineString | Polygon | MultiPolygon,
P extends GeoJsonProperties = GeoJsonProperties,
>(
geojson: Feature<G, P> | FeatureCollection<G, P> | G,
options?: {
/**
* Iterate over 2-vertex line segment in any GeoJSON object, similar to Array.forEach()
* (Multi)Point geometries do not contain segments therefore they are ignored during this operation.
*
* @param {AllGeoJSON} geojson any GeoJSON
* @param {segmentEachCallback} callback a method that takes (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex)
* @returns {void}
* @example
* var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
*
* // Iterate over GeoJSON by 2-vertex segments
* turf.segmentEach(polygon, function (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) {
* //=currentSegment
* //=featureIndex
* //=multiFeatureIndex
* //=geometryIndex
* //=segmentIndex
* });
*
* // Calculate the total number of segments
* var total = 0;
* turf.segmentEach(polygon, function () {
* total++;
* });
*/
declare function segmentEach<P extends GeoJsonProperties = GeoJsonProperties>(geojson: AllGeoJSON, callback: (currentSegment?: Feature<LineString, P>, featureIndex?: number, multiFeatureIndex?: number, segmentIndex?: number, geometryIndex?: number) => void): void;
/**
* Callback for segmentReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback segmentReduceCallback
* @param {Reducer} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {Feature<LineString>} currentSegment The current Segment being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
* @param {number} geometryIndex The current index of the Geometry being processed.
* @param {number} segmentIndex The current index of the Segment being processed.
* @returns {Reducer}
*/
/**
* Reduce 2-vertex line segment in any GeoJSON object, similar to Array.reduce()
* (Multi)Point geometries do not contain segments therefore they are ignored during this operation.
*
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON
* @param {segmentReduceCallback} callback a method that takes (previousValue, currentSegment, currentIndex)
* @param {Reducer} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {Reducer}
* @example
* var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
*
* // Iterate over GeoJSON by 2-vertex segments
* turf.segmentReduce(polygon, function (previousSegment, currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) {
* //= previousSegment
* //= currentSegment
* //= featureIndex
* //= multiFeatureIndex
* //= geometryIndex
* //= segmentIndex
* return currentSegment
* });
*
* // Calculate the total number of segments
* var initialValue = 0
* var total = turf.segmentReduce(polygon, function (previousValue) {
* previousValue++;
* return previousValue;
* }, initialValue);
*/
declare function segmentReduce<Reducer, P extends GeoJsonProperties = GeoJsonProperties>(geojson: FeatureCollection<Lines, P> | Feature<Lines, P> | Lines | Feature<GeometryCollection, P> | GeometryCollection, callback: (previousValue?: Reducer, currentSegment?: Feature<LineString, P>, featureIndex?: number, multiFeatureIndex?: number, segmentIndex?: number, geometryIndex?: number) => Reducer, initialValue?: Reducer): Reducer;
/**
* Callback for lineEach
*
* @callback lineEachCallback
* @param {Feature<LineString>} currentLine The current LineString|LinearRing being processed
* @param {number} featureIndex The current index of the Feature being processed
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed
* @param {number} geometryIndex The current index of the Geometry being processed
* @returns {void}
*/
/**
* Iterate over line or ring coordinates in LineString, Polygon, MultiLineString, MultiPolygon Features or Geometries,
* similar to Array.forEach.
*
* @function
* @param {FeatureCollection<Lines>|Feature<Lines>|Lines|Feature<GeometryCollection>|GeometryCollection} geojson object
* @param {lineEachCallback} callback a method that takes (currentLine, featureIndex, multiFeatureIndex, geometryIndex)
* @returns {void}
* @example
* var multiLine = turf.multiLineString([
* [[26, 37], [35, 45]],
* [[36, 53], [38, 50], [41, 55]]
* ]);
*
* turf.lineEach(multiLine, function (currentLine, featureIndex, multiFeatureIndex, geometryIndex) {
* //=currentLine
* //=featureIndex
* //=multiFeatureIndex
* //=geometryIndex
* });
*/
declare function lineEach<P extends GeoJsonProperties = GeoJsonProperties>(geojson: FeatureCollection<Lines, P> | Feature<Lines, P> | Lines | Feature<GeometryCollection, P> | GeometryCollection, callback: (currentLine: Feature<LineString, P>, featureIndex?: number, multiFeatureIndex?: number, geometryIndex?: number) => void): void;
/**
* Callback for lineReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback lineReduceCallback
* @param {Reducer} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {Feature<LineString>} currentLine The current LineString|LinearRing being processed.
* @param {number} featureIndex The current index of the Feature being processed
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed
* @param {number} geometryIndex The current index of the Geometry being processed
* @returns {Reducer}
*/
/**
* Reduce features in any GeoJSON object, similar to Array.reduce().
*
* @function
* @param {FeatureCollection<Lines>|Feature<Lines>|Lines|Feature<GeometryCollection>|GeometryCollection} geojson object
* @param {Function} callback a method that takes (previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex)
* @param {Reducer} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {Reducer} The value that results from the reduction.
* @example
* var multiPoly = turf.multiPolygon([
* turf.polygon([[[12,48],[2,41],[24,38],[12,48]], [[9,44],[13,41],[13,45],[9,44]]]),
* turf.polygon([[[5, 5], [0, 0], [2, 2], [4, 4], [5, 5]]])
* ]);
*
* turf.lineReduce(multiPoly, function (previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex) {
* //=previousValue
* //=currentLine
* //=featureIndex
* //=multiFeatureIndex
* //=geometryIndex
* return currentLine
* });
*/
declare function lineReduce<Reducer, P extends GeoJsonProperties = GeoJsonProperties>(geojson: FeatureCollection<Lines, P> | Feature<Lines, P> | Lines | Feature<GeometryCollection, P> | GeometryCollection, callback: (previousValue?: Reducer, currentLine?: Feature<LineString, P>, featureIndex?: number, multiFeatureIndex?: number, geometryIndex?: number) => Reducer, initialValue?: Reducer): Reducer;
/**
* Finds a particular 2-vertex LineString Segment from a GeoJSON using `@turf/meta` indexes.
*
* Negative indexes are permitted.
* Point & MultiPoint will always return null.
*
* @param {FeatureCollection|Feature|Geometry} geojson Any GeoJSON Feature or Geometry
* @param {Object} [options={}] Optional parameters
* @param {number} [options.featureIndex=0] Feature Index
* @param {number} [options.multiFeatureIndex=0] Multi-Feature Index
* @param {number} [options.geometryIndex=0] Geometry Index
* @param {number} [options.segmentIndex=0] Segment Index
* @param {Object} [options.properties={}] Translate Properties to output LineString
* @param {BBox} [options.bbox={}] Translate BBox to output LineString
* @param {number|string} [options.id={}] Translate Id to output LineString
* @returns {Feature<LineString>} 2-vertex GeoJSON Feature LineString
* @example
* var multiLine = turf.multiLineString([
* [[10, 10], [50, 30], [30, 40]],
* [[-10, -10], [-50, -30], [-30, -40]]
* ]);
*
* // First Segment (defaults are 0)
* turf.findSegment(multiLine);
* // => Feature<LineString<[[10, 10], [50, 30]]>>
*
* // First Segment of 2nd Multi Feature
* turf.findSegment(multiLine, {multiFeatureIndex: 1});
* // => Feature<LineString<[[-10, -10], [-50, -30]]>>
*
* // Last Segment of Last Multi Feature
* turf.findSegment(multiLine, {multiFeatureIndex: -1, segmentIndex: -1});
* // => Feature<LineString<[[-50, -30], [-30, -40]]>>
*/
declare function findSegment<G extends LineString | MultiLineString | Polygon | MultiPolygon, P extends GeoJsonProperties = GeoJsonProperties>(geojson: Feature<G, P> | FeatureCollection<G, P> | G, options?: {
featureIndex?: number;

@@ -284,14 +618,37 @@ multiFeatureIndex?: number;

id?: Id;
}
): Feature<LineString, P>;
}): Feature<LineString, P>;
/**
* http://turfjs.org/docs/#findpoint
* Finds a particular Point from a GeoJSON using `@turf/meta` indexes.
*
* Negative indexes are permitted.
*
* @param {FeatureCollection|Feature|Geometry} geojson Any GeoJSON Feature or Geometry
* @param {Object} [options={}] Optional parameters
* @param {number} [options.featureIndex=0] Feature Index
* @param {number} [options.multiFeatureIndex=0] Multi-Feature Index
* @param {number} [options.geometryIndex=0] Geometry Index
* @param {number} [options.coordIndex=0] Coord Index
* @param {Object} [options.properties={}] Translate Properties to output Point
* @param {BBox} [options.bbox={}] Translate BBox to output Point
* @param {number|string} [options.id={}] Translate Id to output Point
* @returns {Feature<Point>} 2-vertex GeoJSON Feature Point
* @example
* var multiLine = turf.multiLineString([
* [[10, 10], [50, 30], [30, 40]],
* [[-10, -10], [-50, -30], [-30, -40]]
* ]);
*
* // First Segment (defaults are 0)
* turf.findPoint(multiLine);
* // => Feature<Point<[10, 10]>>
*
* // First Segment of the 2nd Multi-Feature
* turf.findPoint(multiLine, {multiFeatureIndex: 1});
* // => Feature<Point<[-10, -10]>>
*
* // Last Segment of last Multi-Feature
* turf.findPoint(multiLine, {multiFeatureIndex: -1, coordIndex: -1});
* // => Feature<Point<[-30, -40]>>
*/
declare function findPoint<
G extends GeometryObject,
P extends GeoJsonProperties = GeoJsonProperties,
>(
geojson: Feature<G, P> | FeatureCollection<G, P> | G,
options?: {
declare function findPoint<G extends GeometryObject, P extends GeoJsonProperties = GeoJsonProperties>(geojson: Feature<G, P> | FeatureCollection<G, P> | G, options?: {
featureIndex?: number;

@@ -304,5 +661,4 @@ multiFeatureIndex?: number;

id?: Id;
}
): Feature<Point, P>;
}): Feature<Point, P>;
export { coordAll, coordEach, coordReduce, featureEach, featureReduce, findPoint, findSegment, flattenEach, flattenReduce, geomEach, geomReduce, lineEach, lineReduce, propEach, propReduce, segmentEach, segmentReduce };

@@ -1,2 +0,2 @@

// index.js
// index.ts
import { feature, point, lineString, isObject } from "@turf/helpers";

@@ -7,3 +7,9 @@ function coordEach(geojson, callback, excludeWrapCoord) {

for (var featureIndex = 0; featureIndex < stop; featureIndex++) {
geometryMaybeCollection = isFeatureCollection ? geojson.features[featureIndex].geometry : isFeature ? geojson.geometry : geojson;
geometryMaybeCollection = isFeatureCollection ? (
// @ts-expect-error: Known type conflict
geojson.features[featureIndex].geometry
) : isFeature ? (
// @ts-expect-error: Known type conflict
geojson.geometry
) : geojson;
isGeometryCollection = geometryMaybeCollection ? geometryMaybeCollection.type === "GeometryCollection" : false;

@@ -23,9 +29,12 @@ stopG = isGeometryCollection ? geometryMaybeCollection.geometries.length : 1;

case "Point":
if (callback(
coords,
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) === false)
if (
// @ts-expect-error: Known type conflict
callback(
coords,
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) === false
)
return false;

@@ -38,9 +47,12 @@ coordIndex++;

for (j = 0; j < coords.length; j++) {
if (callback(
coords[j],
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) === false)
if (
// @ts-expect-error: Known type conflict
callback(
coords[j],
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) === false
)
return false;

@@ -56,9 +68,12 @@ coordIndex++;

for (k = 0; k < coords[j].length - wrapShrink; k++) {
if (callback(
coords[j][k],
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) === false)
if (
// @ts-expect-error: Known type conflict
callback(
coords[j][k],
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) === false
)
return false;

@@ -77,9 +92,12 @@ coordIndex++;

for (l = 0; l < coords[j][k].length - wrapShrink; l++) {
if (callback(
coords[j][k][l],
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) === false)
if (
// @ts-expect-error: Known type conflict
callback(
coords[j][k][l],
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) === false
)
return false;

@@ -95,3 +113,6 @@ coordIndex++;

for (j = 0; j < geometry.geometries.length; j++)
if (coordEach(geometry.geometries[j], callback, excludeWrapCoord) === false)
if (
// @ts-expect-error: Known type conflict
coordEach(geometry.geometries[j], callback, excludeWrapCoord) === false
)
return false;

@@ -114,2 +135,3 @@ break;

previousValue = callback(
// @ts-expect-error: Known type conflict
previousValue,

@@ -178,6 +200,30 @@ currentCoord,

for (i = 0; i < stop; i++) {
geometryMaybeCollection = isFeatureCollection ? geojson.features[i].geometry : isFeature ? geojson.geometry : geojson;
featureProperties = isFeatureCollection ? geojson.features[i].properties : isFeature ? geojson.properties : {};
featureBBox = isFeatureCollection ? geojson.features[i].bbox : isFeature ? geojson.bbox : void 0;
featureId = isFeatureCollection ? geojson.features[i].id : isFeature ? geojson.id : void 0;
geometryMaybeCollection = isFeatureCollection ? (
// @ts-expect-error: Known type conflict
geojson.features[i].geometry
) : isFeature ? (
// @ts-expect-error: Known type conflict
geojson.geometry
) : geojson;
featureProperties = isFeatureCollection ? (
// @ts-expect-error: Known type conflict
geojson.features[i].properties
) : isFeature ? (
// @ts-expect-error: Known type conflict
geojson.properties
) : {};
featureBBox = isFeatureCollection ? (
// @ts-expect-error: Known type conflict
geojson.features[i].bbox
) : isFeature ? (
// @ts-expect-error: Known type conflict
geojson.bbox
) : void 0;
featureId = isFeatureCollection ? (
// @ts-expect-error: Known type conflict
geojson.features[i].id
) : isFeature ? (
// @ts-expect-error: Known type conflict
geojson.id
) : void 0;
isGeometryCollection = geometryMaybeCollection ? geometryMaybeCollection.type === "GeometryCollection" : false;

@@ -188,9 +234,13 @@ stopG = isGeometryCollection ? geometryMaybeCollection.geometries.length : 1;

if (geometry === null) {
if (callback(
null,
featureIndex,
featureProperties,
featureBBox,
featureId
) === false)
if (
// @ts-expect-error: Known type conflict
callback(
// @ts-expect-error: Known type conflict
null,
featureIndex,
featureProperties,
featureBBox,
featureId
) === false
)
return false;

@@ -206,9 +256,12 @@ continue;

case "MultiPolygon": {
if (callback(
geometry,
featureIndex,
featureProperties,
featureBBox,
featureId
) === false)
if (
// @ts-expect-error: Known type conflict
callback(
geometry,
featureIndex,
featureProperties,
featureBBox,
featureId
) === false
)
return false;

@@ -219,9 +272,12 @@ break;

for (j = 0; j < geometry.geometries.length; j++) {
if (callback(
geometry.geometries[j],
featureIndex,
featureProperties,
featureBBox,
featureId
) === false)
if (
// @ts-expect-error: Known type conflict
callback(
geometry.geometries[j],
featureIndex,
featureProperties,
featureBBox,
featureId
) === false
)
return false;

@@ -247,2 +303,3 @@ }

previousValue = callback(
// @ts-expect-error: Known type conflict
previousValue,

@@ -267,7 +324,10 @@ currentGeometry,

case "Polygon":
if (callback(
feature(geometry, properties, { bbox, id }),
featureIndex,
0
) === false)
if (
// @ts-expect-error: Known type conflict
callback(
feature(geometry, properties, { bbox, id }),
featureIndex,
0
) === false
)
return false;

@@ -288,3 +348,8 @@ return;

}
for (var multiFeatureIndex = 0; multiFeatureIndex < geometry.coordinates.length; multiFeatureIndex++) {
for (
var multiFeatureIndex = 0;
// @ts-expect-error: Known type conflict
multiFeatureIndex < geometry.coordinates.length;
multiFeatureIndex++
) {
var coordinate = geometry.coordinates[multiFeatureIndex];

@@ -295,3 +360,6 @@ var geom = {

};
if (callback(feature(geom, properties), featureIndex, multiFeatureIndex) === false)
if (
// @ts-expect-error: Known type conflict
callback(feature(geom, properties), featureIndex, multiFeatureIndex) === false
)
return false;

@@ -310,2 +378,3 @@ }

previousValue = callback(
// @ts-expect-error: Known type conflict
previousValue,

@@ -330,29 +399,40 @@ currentFeature,

var prevGeomIndex = 0;
if (coordEach(
feature2,
function(currentCoord, coordIndex, featureIndexCoord, multiPartIndexCoord, geometryIndex) {
if (previousCoords === void 0 || featureIndex > previousFeatureIndex || multiPartIndexCoord > previousMultiIndex || geometryIndex > prevGeomIndex) {
if (
// @ts-expect-error: Known type conflict
coordEach(
feature2,
function(currentCoord, coordIndex, featureIndexCoord, multiPartIndexCoord, geometryIndex) {
if (
// @ts-expect-error: Known type conflict
previousCoords === void 0 || featureIndex > previousFeatureIndex || multiPartIndexCoord > previousMultiIndex || geometryIndex > prevGeomIndex
) {
previousCoords = currentCoord;
previousFeatureIndex = featureIndex;
previousMultiIndex = multiPartIndexCoord;
prevGeomIndex = geometryIndex;
segmentIndex = 0;
return;
}
var currentSegment = lineString(
// @ts-expect-error: Known type conflict
[previousCoords, currentCoord],
feature2.properties
);
if (
// @ts-expect-error: Known type conflict
callback(
// @ts-expect-error: Known type conflict
currentSegment,
featureIndex,
multiFeatureIndex,
geometryIndex,
segmentIndex
) === false
)
return false;
segmentIndex++;
previousCoords = currentCoord;
previousFeatureIndex = featureIndex;
previousMultiIndex = multiPartIndexCoord;
prevGeomIndex = geometryIndex;
segmentIndex = 0;
return;
}
var currentSegment = lineString(
[previousCoords, currentCoord],
feature2.properties
);
if (callback(
currentSegment,
featureIndex,
multiFeatureIndex,
geometryIndex,
segmentIndex
) === false)
return false;
segmentIndex++;
previousCoords = currentCoord;
}
) === false)
) === false
)
return false;

@@ -372,2 +452,3 @@ });

previousValue,
// @ts-expect-error: Known type conflict
currentSegment,

@@ -397,8 +478,12 @@ featureIndex,

for (var geometryIndex = 0; geometryIndex < coords.length; geometryIndex++) {
if (callback(
lineString(coords[geometryIndex], feature2.properties),
featureIndex,
multiFeatureIndex,
geometryIndex
) === false)
if (
// @ts-expect-error: Known type conflict
callback(
// @ts-expect-error: Known type conflict
lineString(coords[geometryIndex], feature2.properties),
featureIndex,
multiFeatureIndex,
geometryIndex
) === false
)
return false;

@@ -470,2 +555,3 @@ }

return lineString(
// @ts-expect-error: Known type conflict
[coords[segmentIndex], coords[segmentIndex + 1]],

@@ -481,3 +567,5 @@ properties,

[
// @ts-expect-error: Known type conflict
coords[geometryIndex][segmentIndex],
// @ts-expect-error: Known type conflict
coords[geometryIndex][segmentIndex + 1]

@@ -495,3 +583,5 @@ ],

[
// @ts-expect-error: Known type conflict
coords[multiFeatureIndex][segmentIndex],
// @ts-expect-error: Known type conflict
coords[multiFeatureIndex][segmentIndex + 1]

@@ -508,6 +598,9 @@ ],

if (segmentIndex < 0)
segmentIndex = coords[multiFeatureIndex][geometryIndex].length - segmentIndex - 1;
segmentIndex = // @ts-expect-error: Known type conflict
coords[multiFeatureIndex][geometryIndex].length - segmentIndex - 1;
return lineString(
[
// @ts-expect-error: Known type conflict
coords[multiFeatureIndex][geometryIndex][segmentIndex],
// @ts-expect-error: Known type conflict
coords[multiFeatureIndex][geometryIndex][segmentIndex + 1]

@@ -514,0 +607,0 @@ ],

{
"name": "@turf/meta",
"version": "7.3.1",
"version": "7.3.2",
"description": "Provides tools for iterating over and manipulating GeoJSON objects.",

@@ -76,14 +76,17 @@ "author": "Turf Authors",

"devDependencies": {
"@turf/random": "7.3.1",
"@turf/random": "7.3.2",
"@types/benchmark": "^2.1.5",
"@types/tape": "^5.8.1",
"benchmark": "^2.1.4",
"tape": "^5.9.0",
"tsup": "^8.4.0",
"tsx": "^4.19.4"
"tsx": "^4.19.4",
"typescript": "^5.8.3"
},
"dependencies": {
"@turf/helpers": "7.3.1",
"@types/geojson": "^7946.0.10"
"@turf/helpers": "7.3.2",
"@types/geojson": "^7946.0.10",
"tslib": "^2.8.1"
},
"gitHead": "b7f1b4eafb760431e03955499d8eac9489438219"
"gitHead": "099d9915467bacf45d554be4533fa9998c4efc88"
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display