@turf/meta
Advanced tools
Comparing version 5.0.4 to 5.1.0
140
index.d.ts
@@ -13,5 +13,5 @@ import { | ||
AllGeoJSON, | ||
FeatureGeometryCollection, | ||
ExtendedFeatureCollection, | ||
Properties, | ||
Geometries, | ||
Lines, | ||
BBox, | ||
@@ -26,3 +26,8 @@ Id | ||
geojson: AllGeoJSON, | ||
callback: (previousValue: Reducer, currentCoord: number[], coordIndex: number, featureIndex: number, featureSubIndex: number) => Reducer, | ||
callback: (previousValue: Reducer, | ||
currentCoord: number[], | ||
coordIndex: number, | ||
featureIndex: number, | ||
multiFeatureIndex: number, | ||
geometryIndex: number) => Reducer, | ||
initialValue?: Reducer | ||
@@ -36,3 +41,7 @@ ): Reducer; | ||
geojson: AllGeoJSON, | ||
callback: (currentCoord: number[], coordIndex: number, featureIndex: number, featureSubIndex: number) => void | ||
callback: (currentCoord: number[], | ||
coordIndex: number, | ||
featureIndex: number, | ||
multiFeatureIndex: number, | ||
geometryIndex: number) => void | ||
): void; | ||
@@ -44,4 +53,5 @@ | ||
export function propEach<Props extends Properties>( | ||
geojson: Feature<any> | FeatureCollection<any> | FeatureGeometryCollection, | ||
callback: (currentProperties: Props, featureIndex: number) => void | ||
geojson: Feature<any> | FeatureCollection<any> | Feature<GeometryCollection>, | ||
callback: (currentProperties: Props, | ||
featureIndex: number) => void | ||
): void; | ||
@@ -52,5 +62,7 @@ | ||
*/ | ||
export function propReduce<Reducer extends any, Props extends Properties>( | ||
geojson: Feature<any> | FeatureCollection<any> | FeatureGeometryCollection, | ||
callback: (previousValue: Reducer, currentProperties: Props, featureIndex: number) => Reducer, | ||
export function propReduce<Reducer extends any, P = Properties>( | ||
geojson: Feature<any, P> | FeatureCollection<any, P> | Geometries | GeometryCollection, | ||
callback: (previousValue: Reducer, | ||
currentProperties: P, | ||
featureIndex: number) => Reducer, | ||
initialValue?: Reducer | ||
@@ -62,12 +74,9 @@ ): Reducer; | ||
*/ | ||
export function featureReduce<Reducer extends any, Geom extends GeometryObject>( | ||
geojson: Feature<Geom> | FeatureCollection<Geom> | FeatureGeometryCollection, | ||
callback: (previousValue: Reducer, currentFeature: Feature<Geom>, featureIndex: number) => Reducer, | ||
export function featureReduce<Reducer extends any, G extends Geometries, P = Properties>( | ||
geojson: Feature<G, P> | FeatureCollection<G, P> | Feature<GeometryCollection, P>, | ||
callback: (previousValue: Reducer, | ||
currentFeature: Feature<G, P>, | ||
featureIndex: number) => Reducer, | ||
initialValue?: Reducer | ||
): Reducer; | ||
export function featureReduce<Reducer extends any, Feat extends Feature<any>>( | ||
geojson: Feat | ExtendedFeatureCollection<Feat>, | ||
callback: (previousValue: Reducer, currentFeature: Feat, featureIndex: number) => Reducer, | ||
initialValue?: Reducer | ||
): Reducer; | ||
@@ -77,10 +86,7 @@ /** | ||
*/ | ||
export function featureEach<Geom extends GeometryObject>( | ||
geojson: Feature<Geom> | FeatureCollection<Geom> | FeatureGeometryCollection, | ||
callback: (currentFeature: Feature<Geom>, featureIndex: number) => void | ||
export function featureEach<G extends Geometries, P = Properties>( | ||
geojson: Feature<G, P> | FeatureCollection<G, P> | Feature<GeometryCollection, P>, | ||
callback: (currentFeature: Feature<G, P>, | ||
featureIndex: number) => void | ||
): void; | ||
export function featureEach<Feat extends Feature<any>>( | ||
geojson: Feat | ExtendedFeatureCollection<Feat>, | ||
callback: (currentFeature: Feat, featureIndex: number) => void | ||
): void; | ||
@@ -95,5 +101,10 @@ /** | ||
*/ | ||
export function geomReduce<Reducer extends any, Geom extends GeometryObject>( | ||
geojson: Feature<Geom> | FeatureCollection<Geom> | Geom | GeometryCollection | FeatureGeometryCollection, | ||
callback: (previousValue: Reducer, currentGeometry: Geom, featureIndex: number, currentProperties: Properties, currentBBox: BBox, currentId: Id) => Reducer, | ||
export function geomReduce<Reducer extends any, G extends Geometries, P = Properties>( | ||
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 | ||
@@ -105,5 +116,9 @@ ): Reducer; | ||
*/ | ||
export function geomEach<Geom extends GeometryObject>( | ||
geojson: Feature<Geom> | FeatureCollection<Geom> | Geom | GeometryCollection | FeatureGeometryCollection, | ||
callback: (currentGeometry: Geom, featureIndex: number, currentProperties: Properties, currentBBox: BBox, currentId: Id) => void | ||
export function geomEach<G extends Geometries, P = Properties>( | ||
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; | ||
@@ -114,5 +129,8 @@ | ||
*/ | ||
export function flattenReduce<Reducer extends any, Geom extends GeometryObject>( | ||
geojson: Feature<Geom> | FeatureCollection<Geom> | Geom | GeometryCollection | FeatureGeometryCollection, | ||
callback: (previousValue: Reducer, currentFeature: Feature<Geom>, featureIndex: number, featureSubIndex: number) => Reducer, | ||
export function flattenReduce<Reducer extends any, G extends Geometries, P = Properties>( | ||
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 | ||
@@ -124,5 +142,7 @@ ): Reducer; | ||
*/ | ||
export function flattenEach<Geom extends GeometryObject>( | ||
geojson: Feature<Geom> | FeatureCollection<Geom> | Geom | GeometryCollection | FeatureGeometryCollection, | ||
callback: (currentFeature: Feature<Geom>, featureIndex: number, featureSubIndex: number) => void | ||
export function flattenEach<G = Geometries, P = Properties>( | ||
geojson: Feature<G, P> | FeatureCollection<G, P> | G | GeometryCollection | Feature<GeometryCollection, P>, | ||
callback: (currentFeature: Feature<G, P>, | ||
featureIndex: number, | ||
multiFeatureIndex: number) => void | ||
): void; | ||
@@ -133,5 +153,10 @@ | ||
*/ | ||
export function segmentReduce<Reducer extends any>( | ||
geojson: Feature<any> | FeatureCollection<any> | GeometryObject | GeometryCollection | FeatureGeometryCollection, | ||
callback: (previousValue?: Reducer, currentSegment?: Feature<LineString>, featureIndex?: number, featureSubIndex?: number, segmentIndex?: number) => Reducer, | ||
export function segmentReduce<Reducer extends any, P = Properties>( | ||
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 | ||
@@ -143,5 +168,9 @@ ): Reducer; | ||
*/ | ||
export function segmentEach( | ||
geojson: Feature<any> | FeatureCollection<any> | GeometryObject | GeometryCollection | FeatureGeometryCollection, | ||
callback: (currentSegment?: Feature<LineString>, featureIndex?: number, featureSubIndex?: number, segmentIndex?: number) => void | ||
export function segmentEach<P = Properties>( | ||
geojson: AllGeoJSON, | ||
callback: (currentSegment?: Feature<LineString, P>, | ||
featureIndex?: number, | ||
multiFeatureIndex?: number, | ||
segmentIndex?: number, | ||
geometryIndex?: number) => void | ||
): void; | ||
@@ -152,5 +181,9 @@ | ||
*/ | ||
export function lineReduce<Reducer extends any>( | ||
geojson: AllGeoJSON, | ||
callback: (previousValue?: Reducer, currentLine?: Feature<LineString>, featureIndex?: number, featureSubIndex?: number, lineIndex?: number) => Reducer, | ||
export function lineReduce<Reducer extends any, P = Properties>( | ||
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 | ||
@@ -162,13 +195,8 @@ ): Reducer; | ||
*/ | ||
export function lineEach<T extends LineString | MultiLineString | Polygon | MultiPolygon>( | ||
geojson: Feature<T> | T, | ||
callback: (currentLine?: Feature<LineString>, featureIndex?: number, featureSubIndex?: number, lineIndex?: number) => void | ||
export function lineEach<P = Properties>( | ||
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; | ||
export function lineEach<Feat extends Feature<LineString>>( | ||
geojson: Feat | ExtendedFeatureCollection<Feat>, | ||
callback: (currentLine?: Feat, featureIndex?: number, featureSubIndex?: number, lineIndex?: number) => void | ||
): void; | ||
export function lineEach<Feat extends Feature<MultiLineString | Polygon | MultiPolygon>>( | ||
geojson: Feat | ExtendedFeatureCollection<Feat>, | ||
callback: (currentLine?: Feature<LineString>, featureIndex?: number, featureSubIndex?: number, lineIndex?: number) => void | ||
): void; |
277
index.js
@@ -9,5 +9,5 @@ import { feature, lineString } from '@turf/helpers'; | ||
* @param {number} coordIndex The current index of the coordinate being processed. | ||
* Starts at index 0. | ||
* @param {number} featureIndex The current index of the feature being processed. | ||
* @param {number} featureSubIndex The current subIndex of the 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. | ||
* @param {number} geometryIndex The current index of the Geometry being processed. | ||
*/ | ||
@@ -19,4 +19,4 @@ | ||
* @name coordEach | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (currentCoord, coordIndex, featureIndex, featureSubIndex) | ||
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object | ||
* @param {Function} 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. | ||
@@ -29,7 +29,8 @@ * @example | ||
* | ||
* turf.coordEach(features, function (currentCoord, coordIndex, featureIndex, featureSubIndex) { | ||
* turf.coordEach(features, function (currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) { | ||
* //=currentCoord | ||
* //=coordIndex | ||
* //=featureIndex | ||
* //=featureSubIndex | ||
* //=multiFeatureIndex | ||
* //=geometryIndex | ||
* }); | ||
@@ -40,3 +41,3 @@ */ | ||
if (geojson === null) return; | ||
var featureIndex, geometryIndex, j, k, l, geometry, stopG, coords, | ||
var j, k, l, geometry, stopG, coords, | ||
geometryMaybeCollection, | ||
@@ -63,3 +64,3 @@ wrapShrink = 0, | ||
// be required with the normalization approach. | ||
for (featureIndex = 0; featureIndex < stop; featureIndex++) { | ||
for (var featureIndex = 0; featureIndex < stop; featureIndex++) { | ||
geometryMaybeCollection = (isFeatureCollection ? geojson.features[featureIndex].geometry : | ||
@@ -70,6 +71,7 @@ (isFeature ? geojson.geometry : geojson)); | ||
for (geometryIndex = 0; geometryIndex < stopG; geometryIndex++) { | ||
var featureSubIndex = 0; | ||
for (var geomIndex = 0; geomIndex < stopG; geomIndex++) { | ||
var multiFeatureIndex = 0; | ||
var geometryIndex = 0; | ||
geometry = isGeometryCollection ? | ||
geometryMaybeCollection.geometries[geometryIndex] : geometryMaybeCollection; | ||
geometryMaybeCollection.geometries[geomIndex] : geometryMaybeCollection; | ||
@@ -87,5 +89,5 @@ // Handles null Geometry -- Skips this geometry | ||
case 'Point': | ||
callback(coords, coordIndex, featureIndex, featureSubIndex); | ||
callback(coords, coordIndex, featureIndex, multiFeatureIndex, geometryIndex); | ||
coordIndex++; | ||
featureSubIndex++; | ||
multiFeatureIndex++; | ||
break; | ||
@@ -95,7 +97,7 @@ case 'LineString': | ||
for (j = 0; j < coords.length; j++) { | ||
callback(coords[j], coordIndex, featureIndex, featureSubIndex); | ||
callback(coords[j], coordIndex, featureIndex, multiFeatureIndex, geometryIndex); | ||
coordIndex++; | ||
if (geomType === 'MultiPoint') featureSubIndex++; | ||
if (geomType === 'MultiPoint') multiFeatureIndex++; | ||
} | ||
if (geomType === 'LineString') featureSubIndex++; | ||
if (geomType === 'LineString') multiFeatureIndex++; | ||
break; | ||
@@ -106,17 +108,20 @@ case 'Polygon': | ||
for (k = 0; k < coords[j].length - wrapShrink; k++) { | ||
callback(coords[j][k], coordIndex, featureIndex, featureSubIndex); | ||
callback(coords[j][k], coordIndex, featureIndex, multiFeatureIndex, geometryIndex); | ||
coordIndex++; | ||
} | ||
if (geomType === 'MultiLineString') featureSubIndex++; | ||
if (geomType === 'MultiLineString') multiFeatureIndex++; | ||
if (geomType === 'Polygon') geometryIndex++; | ||
} | ||
if (geomType === 'Polygon') featureSubIndex++; | ||
if (geomType === 'Polygon') multiFeatureIndex++; | ||
break; | ||
case 'MultiPolygon': | ||
for (j = 0; j < coords.length; j++) { | ||
for (k = 0; k < coords[j].length; k++) | ||
for (k = 0; k < coords[j].length; k++) { | ||
for (l = 0; l < coords[j][k].length - wrapShrink; l++) { | ||
callback(coords[j][k][l], coordIndex, featureIndex, featureSubIndex); | ||
callback(coords[j][k][l], coordIndex, featureIndex, multiFeatureIndex, geometryIndex); | ||
coordIndex++; | ||
} | ||
featureSubIndex++; | ||
if (geomType === 'Polygon') geometryIndex++; | ||
} | ||
multiFeatureIndex++; | ||
} | ||
@@ -155,4 +160,5 @@ break; | ||
* 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} featureSubIndex The current subIndex of the 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. | ||
* @param {number} geometryIndex The current index of the Geometry being processed. | ||
*/ | ||
@@ -175,3 +181,3 @@ | ||
* | ||
* turf.coordReduce(features, function (previousValue, currentCoord, coordIndex, featureIndex, featureSubIndex) { | ||
* turf.coordReduce(features, function (previousValue, currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) { | ||
* //=previousValue | ||
@@ -181,3 +187,4 @@ * //=currentCoord | ||
* //=featureIndex | ||
* //=featureSubIndex | ||
* //=multiFeatureIndex | ||
* //=geometryIndex | ||
* return currentCoord; | ||
@@ -188,5 +195,5 @@ * }); | ||
var previousValue = initialValue; | ||
coordEach(geojson, function (currentCoord, coordIndex, featureIndex, featureSubIndex) { | ||
coordEach(geojson, function (currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) { | ||
if (coordIndex === 0 && initialValue === undefined) previousValue = currentCoord; | ||
else previousValue = callback(previousValue, currentCoord, coordIndex, featureIndex, featureSubIndex); | ||
else previousValue = callback(previousValue, currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex); | ||
}, excludeWrapCoord); | ||
@@ -200,5 +207,4 @@ return previousValue; | ||
* @callback propEachCallback | ||
* @param {Object} currentProperties The current properties being processed. | ||
* @param {number} featureIndex The index of the current element being processed in the | ||
* array.Starts at index 0, if an initialValue is provided, and at index 1 otherwise. | ||
* @param {Object} currentProperties The current Properties being processed. | ||
* @param {number} featureIndex The current index of the Feature being processed. | ||
*/ | ||
@@ -210,3 +216,3 @@ | ||
* @name propEach | ||
* @param {(FeatureCollection|Feature)} geojson any GeoJSON object | ||
* @param {FeatureCollection|Feature} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (currentProperties, featureIndex) | ||
@@ -256,5 +262,4 @@ * @example | ||
* of the callback, or initialValue, if supplied. | ||
* @param {*} currentProperties The current properties being processed. | ||
* @param {number} featureIndex The index of the current element being processed in the | ||
* array.Starts at index 0, if an initialValue is provided, and at index 1 otherwise. | ||
* @param {*} currentProperties The current Properties being processed. | ||
* @param {number} featureIndex The current index of the Feature being processed. | ||
*/ | ||
@@ -268,3 +273,3 @@ | ||
* @name propReduce | ||
* @param {(FeatureCollection|Feature)} geojson any GeoJSON object | ||
* @param {FeatureCollection|Feature} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (previousValue, currentProperties, featureIndex) | ||
@@ -299,5 +304,4 @@ * @param {*} [initialValue] Value to use as the first argument to the first call of the callback. | ||
* @callback featureEachCallback | ||
* @param {Feature<any>} currentFeature The current feature being processed. | ||
* @param {number} featureIndex The index of the current element being processed in the | ||
* array.Starts at index 0, if an initialValue is provided, and at index 1 otherwise. | ||
* @param {Feature<any>} currentFeature The current Feature being processed. | ||
* @param {number} featureIndex The current index of the Feature being processed. | ||
*/ | ||
@@ -310,3 +314,3 @@ | ||
* @name featureEach | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON object | ||
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (currentFeature, featureIndex) | ||
@@ -352,4 +356,3 @@ * @example | ||
* @param {Feature} currentFeature The current Feature being processed. | ||
* @param {number} featureIndex The index of the current element being processed in the | ||
* array.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. | ||
*/ | ||
@@ -361,3 +364,3 @@ | ||
* @name featureReduce | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON object | ||
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (previousValue, currentFeature, featureIndex) | ||
@@ -392,3 +395,3 @@ * @param {*} [initialValue] Value to use as the first argument to the first call of the callback. | ||
* @name coordAll | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON object | ||
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object | ||
* @returns {Array<Array<number>>} coordinate position array | ||
@@ -416,8 +419,7 @@ * @example | ||
* @callback geomEachCallback | ||
* @param {Geometry} currentGeometry The current geometry being processed. | ||
* @param {number} featureIndex The index of the current element being processed in the | ||
* array. Starts at index 0, if an initialValue is provided, and at index 1 otherwise. | ||
* @param {Object} featureProperties The current feature properties being processed. | ||
* @param {Array<number>} featureBBox The current feature BBox being processed. | ||
* @param {number|string} featureId The current feature Id being processed. | ||
* @param {Geometry} currentGeometry The current Geometry being processed. | ||
* @param {number} featureIndex The current index of the Feature being processed. | ||
* @param {Object} featureProperties The current Feature Properties being processed. | ||
* @param {Array<number>} featureBBox The current Feature BBox being processed. | ||
* @param {number|string} featureId The current Feature Id being processed. | ||
*/ | ||
@@ -429,4 +431,4 @@ | ||
* @name geomEach | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (currentGeometry, featureIndex, currentProperties) | ||
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (currentGeometry, featureIndex, featureProperties, featureBBox, featureId) | ||
* @example | ||
@@ -438,6 +440,8 @@ * var features = turf.featureCollection([ | ||
* | ||
* turf.geomEach(features, function (currentGeometry, featureIndex, currentProperties) { | ||
* turf.geomEach(features, function (currentGeometry, featureIndex, featureProperties, featureBBox, featureId) { | ||
* //=currentGeometry | ||
* //=featureIndex | ||
* //=currentProperties | ||
* //=featureProperties | ||
* //=featureBBox | ||
* //=featureId | ||
* }); | ||
@@ -533,6 +537,7 @@ */ | ||
* of the callback, or initialValue, if supplied. | ||
* @param {Geometry} currentGeometry The current Feature being processed. | ||
* @param {number} currentIndex The index of the current element being processed in the | ||
* array.Starts at index 0, if an initialValue is provided, and at index 1 otherwise. | ||
* @param {Object} currentProperties The current feature properties being processed. | ||
* @param {Geometry} currentGeometry The current Geometry being processed. | ||
* @param {number} featureIndex The current index of the Feature being processed. | ||
* @param {Object} featureProperties The current Feature Properties being processed. | ||
* @param {Array<number>} featureBBox The current Feature BBox being processed. | ||
* @param {number|string} featureId The current Feature Id being processed. | ||
*/ | ||
@@ -544,4 +549,4 @@ | ||
* @name geomReduce | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (previousValue, currentGeometry, featureIndex, currentProperties) | ||
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId) | ||
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback. | ||
@@ -555,7 +560,9 @@ * @returns {*} The value that results from the reduction. | ||
* | ||
* turf.geomReduce(features, function (previousValue, currentGeometry, featureIndex, currentProperties) { | ||
* turf.geomReduce(features, function (previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId) { | ||
* //=previousValue | ||
* //=currentGeometry | ||
* //=featureIndex | ||
* //=currentProperties | ||
* //=featureProperties | ||
* //=featureBBox | ||
* //=featureId | ||
* return currentGeometry | ||
@@ -566,5 +573,5 @@ * }); | ||
var previousValue = initialValue; | ||
geomEach(geojson, function (currentGeometry, currentIndex, currentProperties) { | ||
if (currentIndex === 0 && initialValue === undefined) previousValue = currentGeometry; | ||
else previousValue = callback(previousValue, currentGeometry, currentIndex, currentProperties); | ||
geomEach(geojson, function (currentGeometry, featureIndex, featureProperties, featureBBox, featureId) { | ||
if (featureIndex === 0 && initialValue === undefined) previousValue = currentGeometry; | ||
else previousValue = callback(previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId); | ||
}); | ||
@@ -579,6 +586,4 @@ return previousValue; | ||
* @param {Feature} currentFeature The current flattened feature being processed. | ||
* @param {number} featureIndex The index of the current element being processed in the | ||
* array. Starts at index 0, if an initialValue is provided, and at index 1 otherwise. | ||
* @param {number} featureSubIndex The subindex of the current element being processed in the | ||
* array. Starts at index 0 and increases if the flattened feature was a multi-geometry. | ||
* @param {number} featureIndex The current index of the Feature being processed. | ||
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed. | ||
*/ | ||
@@ -591,4 +596,4 @@ | ||
* @name flattenEach | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (currentFeature, featureIndex, featureSubIndex) | ||
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (currentFeature, featureIndex, multiFeatureIndex) | ||
* @example | ||
@@ -600,6 +605,6 @@ * var features = turf.featureCollection([ | ||
* | ||
* turf.flattenEach(features, function (currentFeature, featureIndex, featureSubIndex) { | ||
* turf.flattenEach(features, function (currentFeature, featureIndex, multiFeatureIndex) { | ||
* //=currentFeature | ||
* //=featureIndex | ||
* //=featureSubIndex | ||
* //=multiFeatureIndex | ||
* }); | ||
@@ -616,3 +621,3 @@ */ | ||
case 'Polygon': | ||
callback(feature(geometry, properties, bbox, id), featureIndex, 0); | ||
callback(feature(geometry, properties, {bbox, id}), featureIndex, 0); | ||
return; | ||
@@ -636,3 +641,3 @@ } | ||
geometry.coordinates.forEach(function (coordinate, featureSubIndex) { | ||
geometry.coordinates.forEach(function (coordinate, multiFeatureIndex) { | ||
var geom = { | ||
@@ -642,3 +647,3 @@ type: geomType, | ||
}; | ||
callback(feature(geom, properties), featureIndex, featureSubIndex); | ||
callback(feature(geom, properties), featureIndex, multiFeatureIndex); | ||
}); | ||
@@ -667,6 +672,4 @@ | ||
* @param {Feature} currentFeature The current Feature being processed. | ||
* @param {number} featureIndex The index of the current element being processed in the | ||
* array.Starts at index 0, if an initialValue is provided, and at index 1 otherwise. | ||
* @param {number} featureSubIndex The subindex of the current element being processed in the | ||
* array. Starts at index 0 and increases if the flattened feature was a multi-geometry. | ||
* @param {number} featureIndex The current index of the Feature being processed. | ||
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed. | ||
*/ | ||
@@ -678,4 +681,4 @@ | ||
* @name flattenReduce | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (previousValue, currentFeature, featureIndex, featureSubIndex) | ||
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (previousValue, currentFeature, featureIndex, multiFeatureIndex) | ||
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback. | ||
@@ -689,7 +692,7 @@ * @returns {*} The value that results from the reduction. | ||
* | ||
* turf.flattenReduce(features, function (previousValue, currentFeature, featureIndex, featureSubIndex) { | ||
* turf.flattenReduce(features, function (previousValue, currentFeature, featureIndex, multiFeatureIndex) { | ||
* //=previousValue | ||
* //=currentFeature | ||
* //=featureIndex | ||
* //=featureSubIndex | ||
* //=multiFeatureIndex | ||
* return currentFeature | ||
@@ -700,5 +703,5 @@ * }); | ||
var previousValue = initialValue; | ||
flattenEach(geojson, function (currentFeature, featureIndex, featureSubIndex) { | ||
if (featureIndex === 0 && featureSubIndex === 0 && initialValue === undefined) previousValue = currentFeature; | ||
else previousValue = callback(previousValue, currentFeature, featureIndex, featureSubIndex); | ||
flattenEach(geojson, function (currentFeature, featureIndex, multiFeatureIndex) { | ||
if (featureIndex === 0 && multiFeatureIndex === 0 && initialValue === undefined) previousValue = currentFeature; | ||
else previousValue = callback(previousValue, currentFeature, featureIndex, multiFeatureIndex); | ||
}); | ||
@@ -712,6 +715,7 @@ return previousValue; | ||
* @callback segmentEachCallback | ||
* @param {Feature<LineString>} currentSegment The current segment being processed. | ||
* @param {number} featureIndex The featureIndex currently being processed, starts at index 0. | ||
* @param {number} featureSubIndex The featureSubIndex currently being processed, starts at index 0. | ||
* @param {number} segmentIndex The segmentIndex currently being processed, starts at index 0. | ||
* @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} | ||
@@ -724,4 +728,4 @@ */ | ||
* | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON | ||
* @param {Function} callback a method that takes (currentSegment, featureIndex, featureSubIndex) | ||
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON | ||
* @param {Function} callback a method that takes (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) | ||
* @returns {void} | ||
@@ -732,7 +736,8 @@ * @example | ||
* // Iterate over GeoJSON by 2-vertex segments | ||
* turf.segmentEach(polygon, function (currentSegment, featureIndex, featureSubIndex, segmentIndex) { | ||
* //= currentSegment | ||
* //= featureIndex | ||
* //= featureSubIndex | ||
* //= segmentIndex | ||
* turf.segmentEach(polygon, function (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) { | ||
* //=currentSegment | ||
* //=featureIndex | ||
* //=multiFeatureIndex | ||
* //=geometryIndex | ||
* //=segmentIndex | ||
* }); | ||
@@ -747,3 +752,3 @@ * | ||
export function segmentEach(geojson, callback) { | ||
flattenEach(geojson, function (feature, featureIndex, featureSubIndex) { | ||
flattenEach(geojson, function (feature, featureIndex, multiFeatureIndex) { | ||
var segmentIndex = 0; | ||
@@ -758,5 +763,5 @@ | ||
// Generate 2-vertex line segments | ||
coordReduce(feature, function (previousCoords, currentCoord) { | ||
coordReduce(feature, function (previousCoords, currentCoord, coordIndex, featureIndexCoord, mutliPartIndexCoord, geometryIndex) { | ||
var currentSegment = lineString([previousCoords, currentCoord], feature.properties); | ||
callback(currentSegment, featureIndex, featureSubIndex, segmentIndex); | ||
callback(currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex); | ||
segmentIndex++; | ||
@@ -783,8 +788,9 @@ return currentCoord; | ||
* @callback segmentReduceCallback | ||
* @param {*} [previousValue] The accumulated value previously returned in the last invocation | ||
* @param {*} 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 featureIndex currently being processed, starts at index 0. | ||
* @param {number} featureSubIndex The featureSubIndex currently being processed, starts at index 0. | ||
* @param {number} segmentIndex The segmentIndex currently being processed, starts at index 0. | ||
* @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. | ||
*/ | ||
@@ -796,3 +802,3 @@ | ||
* | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON | ||
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON | ||
* @param {Function} callback a method that takes (previousValue, currentSegment, currentIndex) | ||
@@ -805,7 +811,8 @@ * @param {*} [initialValue] Value to use as the first argument to the first call of the callback. | ||
* // Iterate over GeoJSON by 2-vertex segments | ||
* turf.segmentReduce(polygon, function (previousSegment, currentSegment, featureIndex, featureSubIndex, segmentIndex) { | ||
* turf.segmentReduce(polygon, function (previousSegment, currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) { | ||
* //= previousSegment | ||
* //= currentSegment | ||
* //= featureIndex | ||
* //= featureSubIndex | ||
* //= multiFeatureIndex | ||
* //= geometryIndex | ||
* //= segmentInex | ||
@@ -825,5 +832,5 @@ * return currentSegment | ||
var started = false; | ||
segmentEach(geojson, function (currentSegment, featureIndex, featureSubIndex, segmentIndex) { | ||
segmentEach(geojson, function (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) { | ||
if (started === false && initialValue === undefined) previousValue = currentSegment; | ||
else previousValue = callback(previousValue, currentSegment, featureIndex, featureSubIndex, segmentIndex); | ||
else previousValue = callback(previousValue, currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex); | ||
started = true; | ||
@@ -838,6 +845,6 @@ }); | ||
* @callback lineEachCallback | ||
* @param {Feature<LineString>} currentLine The current LineString|LinearRing being processed. | ||
* @param {number} featureIndex The feature index of the current element being processed in the array, starts at index 0. | ||
* @param {number} featureSubIndex The feature sub-index of the current line being processed at index 0 | ||
* @param {number} lineIndex The current line being processed at index 0 | ||
* @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 | ||
*/ | ||
@@ -851,3 +858,3 @@ | ||
* @param {Geometry|Feature<LineString|Polygon|MultiLineString|MultiPolygon>} geojson object | ||
* @param {Function} callback a method that takes (currentLine, featureIndex, featureSubIndex, lineIndex) | ||
* @param {Function} callback a method that takes (currentLine, featureIndex, multiFeatureIndex, geometryIndex) | ||
* @example | ||
@@ -859,7 +866,7 @@ * var multiLine = turf.multiLineString([ | ||
* | ||
* turf.lineEach(multiLine, function (currentLine, featureIndex, featureSubIndex, lineIndex) { | ||
* turf.lineEach(multiLine, function (currentLine, featureIndex, multiFeatureIndex, geometryIndex) { | ||
* //=currentLine | ||
* //=featureIndex | ||
* //=featureSubIndex | ||
* //=lineIndex | ||
* //=multiFeatureIndex | ||
* //=geometryIndex | ||
* }); | ||
@@ -871,3 +878,3 @@ */ | ||
flattenEach(geojson, function (feature, featureIndex, featureSubIndex) { | ||
flattenEach(geojson, function (feature, featureIndex, multiFeatureIndex) { | ||
if (feature.geometry === null) return; | ||
@@ -878,7 +885,7 @@ var type = feature.geometry.type; | ||
case 'LineString': | ||
callback(feature, featureIndex, featureSubIndex, 0); | ||
callback(feature, featureIndex, multiFeatureIndex, 0, 0); | ||
break; | ||
case 'Polygon': | ||
for (var lineIndex = 0; lineIndex < coords.length; lineIndex++) { | ||
callback(lineString(coords[lineIndex], feature.properties), featureIndex, featureSubIndex, lineIndex); | ||
for (var geometryIndex = 0; geometryIndex < coords.length; geometryIndex++) { | ||
callback(lineString(coords[geometryIndex], feature.properties), featureIndex, multiFeatureIndex, geometryIndex); | ||
} | ||
@@ -908,5 +915,5 @@ break; | ||
* @param {Feature<LineString>} currentLine The current LineString|LinearRing being processed. | ||
* @param {number} featureIndex The feature index of the current element being processed in the array, starts at index 0. | ||
* @param {number} featureSubIndex The feature sub-index of the current line being processed at index 0 | ||
* @param {number} lineIndex The current line being processed at index 0 | ||
* @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 | ||
*/ | ||
@@ -919,7 +926,7 @@ | ||
* @param {Geometry|Feature<LineString|Polygon|MultiLineString|MultiPolygon>} geojson object | ||
* @param {Function} callback a method that takes (previousValue, currentFeature, featureIndex) | ||
* @param {Function} callback a method that takes (previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex) | ||
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback. | ||
* @returns {*} The value that results from the reduction. | ||
* @example | ||
* var mtp = turf.multiPolygon([ | ||
* var multiPoly = turf.multiPolygon([ | ||
* turf.polygon([[[12,48],[2,41],[24,38],[12,48]], [[9,44],[13,41],[13,45],[9,44]]]), | ||
@@ -929,18 +936,18 @@ * turf.polygon([[[5, 5], [0, 0], [2, 2], [4, 4], [5, 5]]]) | ||
* | ||
* turf.lineReduce(mtp, function (previousValue, currentLine, featureIndex, featureSubIndex, lineIndex) { | ||
* turf.lineReduce(multiPoly, function (previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex) { | ||
* //=previousValue | ||
* //=currentLine | ||
* //=featureIndex | ||
* //=featureSubIndex | ||
* //=lineIndex | ||
* //=multiFeatureIndex | ||
* //=geometryIndex | ||
* return currentLine | ||
* }, 2); | ||
* }); | ||
*/ | ||
export function lineReduce(geojson, callback, initialValue) { | ||
var previousValue = initialValue; | ||
lineEach(geojson, function (currentLine, featureIndex, featureSubIndex, lineIndex) { | ||
lineEach(geojson, function (currentLine, featureIndex, multiFeatureIndex, geometryIndex) { | ||
if (featureIndex === 0 && initialValue === undefined) previousValue = currentLine; | ||
else previousValue = callback(previousValue, currentLine, featureIndex, featureSubIndex, lineIndex); | ||
else previousValue = callback(previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex); | ||
}); | ||
return previousValue; | ||
} |
305
main.js
@@ -13,5 +13,5 @@ 'use strict'; | ||
* @param {number} coordIndex The current index of the coordinate being processed. | ||
* Starts at index 0. | ||
* @param {number} featureIndex The current index of the feature being processed. | ||
* @param {number} featureSubIndex The current subIndex of the 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. | ||
* @param {number} geometryIndex The current index of the Geometry being processed. | ||
*/ | ||
@@ -23,4 +23,4 @@ | ||
* @name coordEach | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (currentCoord, coordIndex, featureIndex, featureSubIndex) | ||
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object | ||
* @param {Function} 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. | ||
@@ -33,7 +33,8 @@ * @example | ||
* | ||
* turf.coordEach(features, function (currentCoord, coordIndex, featureIndex, featureSubIndex) { | ||
* turf.coordEach(features, function (currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) { | ||
* //=currentCoord | ||
* //=coordIndex | ||
* //=featureIndex | ||
* //=featureSubIndex | ||
* //=multiFeatureIndex | ||
* //=geometryIndex | ||
* }); | ||
@@ -43,4 +44,4 @@ */ | ||
// Handles null Geometry -- Skips this GeoJSON | ||
if (geojson === null) return; | ||
var featureIndex, geometryIndex, j, k, l, geometry, stopG, coords, | ||
if (geojson === null) { return; } | ||
var j, k, l, geometry, stopG, coords, | ||
geometryMaybeCollection, | ||
@@ -67,3 +68,3 @@ wrapShrink = 0, | ||
// be required with the normalization approach. | ||
for (featureIndex = 0; featureIndex < stop; featureIndex++) { | ||
for (var featureIndex = 0; featureIndex < stop; featureIndex++) { | ||
geometryMaybeCollection = (isFeatureCollection ? geojson.features[featureIndex].geometry : | ||
@@ -74,9 +75,10 @@ (isFeature ? geojson.geometry : geojson)); | ||
for (geometryIndex = 0; geometryIndex < stopG; geometryIndex++) { | ||
var featureSubIndex = 0; | ||
for (var geomIndex = 0; geomIndex < stopG; geomIndex++) { | ||
var multiFeatureIndex = 0; | ||
var geometryIndex = 0; | ||
geometry = isGeometryCollection ? | ||
geometryMaybeCollection.geometries[geometryIndex] : geometryMaybeCollection; | ||
geometryMaybeCollection.geometries[geomIndex] : geometryMaybeCollection; | ||
// Handles null Geometry -- Skips this geometry | ||
if (geometry === null) continue; | ||
if (geometry === null) { continue; } | ||
coords = geometry.coordinates; | ||
@@ -91,5 +93,5 @@ var geomType = geometry.type; | ||
case 'Point': | ||
callback(coords, coordIndex, featureIndex, featureSubIndex); | ||
callback(coords, coordIndex, featureIndex, multiFeatureIndex, geometryIndex); | ||
coordIndex++; | ||
featureSubIndex++; | ||
multiFeatureIndex++; | ||
break; | ||
@@ -99,7 +101,7 @@ case 'LineString': | ||
for (j = 0; j < coords.length; j++) { | ||
callback(coords[j], coordIndex, featureIndex, featureSubIndex); | ||
callback(coords[j], coordIndex, featureIndex, multiFeatureIndex, geometryIndex); | ||
coordIndex++; | ||
if (geomType === 'MultiPoint') featureSubIndex++; | ||
if (geomType === 'MultiPoint') { multiFeatureIndex++; } | ||
} | ||
if (geomType === 'LineString') featureSubIndex++; | ||
if (geomType === 'LineString') { multiFeatureIndex++; } | ||
break; | ||
@@ -110,17 +112,20 @@ case 'Polygon': | ||
for (k = 0; k < coords[j].length - wrapShrink; k++) { | ||
callback(coords[j][k], coordIndex, featureIndex, featureSubIndex); | ||
callback(coords[j][k], coordIndex, featureIndex, multiFeatureIndex, geometryIndex); | ||
coordIndex++; | ||
} | ||
if (geomType === 'MultiLineString') featureSubIndex++; | ||
if (geomType === 'MultiLineString') { multiFeatureIndex++; } | ||
if (geomType === 'Polygon') { geometryIndex++; } | ||
} | ||
if (geomType === 'Polygon') featureSubIndex++; | ||
if (geomType === 'Polygon') { multiFeatureIndex++; } | ||
break; | ||
case 'MultiPolygon': | ||
for (j = 0; j < coords.length; j++) { | ||
for (k = 0; k < coords[j].length; k++) | ||
for (k = 0; k < coords[j].length; k++) { | ||
for (l = 0; l < coords[j][k].length - wrapShrink; l++) { | ||
callback(coords[j][k][l], coordIndex, featureIndex, featureSubIndex); | ||
callback(coords[j][k][l], coordIndex, featureIndex, multiFeatureIndex, geometryIndex); | ||
coordIndex++; | ||
} | ||
featureSubIndex++; | ||
if (geomType === 'Polygon') { geometryIndex++; } | ||
} | ||
multiFeatureIndex++; | ||
} | ||
@@ -130,3 +135,3 @@ break; | ||
for (j = 0; j < geometry.geometries.length; j++) | ||
coordEach(geometry.geometries[j], callback, excludeWrapCoord); | ||
{ coordEach(geometry.geometries[j], callback, excludeWrapCoord); } | ||
break; | ||
@@ -160,4 +165,5 @@ default: | ||
* 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} featureSubIndex The current subIndex of the 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. | ||
* @param {number} geometryIndex The current index of the Geometry being processed. | ||
*/ | ||
@@ -180,3 +186,3 @@ | ||
* | ||
* turf.coordReduce(features, function (previousValue, currentCoord, coordIndex, featureIndex, featureSubIndex) { | ||
* turf.coordReduce(features, function (previousValue, currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) { | ||
* //=previousValue | ||
@@ -186,3 +192,4 @@ * //=currentCoord | ||
* //=featureIndex | ||
* //=featureSubIndex | ||
* //=multiFeatureIndex | ||
* //=geometryIndex | ||
* return currentCoord; | ||
@@ -193,5 +200,5 @@ * }); | ||
var previousValue = initialValue; | ||
coordEach(geojson, function (currentCoord, coordIndex, featureIndex, featureSubIndex) { | ||
if (coordIndex === 0 && initialValue === undefined) previousValue = currentCoord; | ||
else previousValue = callback(previousValue, currentCoord, coordIndex, featureIndex, featureSubIndex); | ||
coordEach(geojson, function (currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) { | ||
if (coordIndex === 0 && initialValue === undefined) { previousValue = currentCoord; } | ||
else { previousValue = callback(previousValue, currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex); } | ||
}, excludeWrapCoord); | ||
@@ -205,5 +212,4 @@ return previousValue; | ||
* @callback propEachCallback | ||
* @param {Object} currentProperties The current properties being processed. | ||
* @param {number} featureIndex The index of the current element being processed in the | ||
* array.Starts at index 0, if an initialValue is provided, and at index 1 otherwise. | ||
* @param {Object} currentProperties The current Properties being processed. | ||
* @param {number} featureIndex The current index of the Feature being processed. | ||
*/ | ||
@@ -215,3 +221,3 @@ | ||
* @name propEach | ||
* @param {(FeatureCollection|Feature)} geojson any GeoJSON object | ||
* @param {FeatureCollection|Feature} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (currentProperties, featureIndex) | ||
@@ -261,5 +267,4 @@ * @example | ||
* of the callback, or initialValue, if supplied. | ||
* @param {*} currentProperties The current properties being processed. | ||
* @param {number} featureIndex The index of the current element being processed in the | ||
* array.Starts at index 0, if an initialValue is provided, and at index 1 otherwise. | ||
* @param {*} currentProperties The current Properties being processed. | ||
* @param {number} featureIndex The current index of the Feature being processed. | ||
*/ | ||
@@ -273,3 +278,3 @@ | ||
* @name propReduce | ||
* @param {(FeatureCollection|Feature)} geojson any GeoJSON object | ||
* @param {FeatureCollection|Feature} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (previousValue, currentProperties, featureIndex) | ||
@@ -294,4 +299,4 @@ * @param {*} [initialValue] Value to use as the first argument to the first call of the callback. | ||
propEach(geojson, function (currentProperties, featureIndex) { | ||
if (featureIndex === 0 && initialValue === undefined) previousValue = currentProperties; | ||
else previousValue = callback(previousValue, currentProperties, featureIndex); | ||
if (featureIndex === 0 && initialValue === undefined) { previousValue = currentProperties; } | ||
else { previousValue = callback(previousValue, currentProperties, featureIndex); } | ||
}); | ||
@@ -305,5 +310,4 @@ return previousValue; | ||
* @callback featureEachCallback | ||
* @param {Feature<any>} currentFeature The current feature being processed. | ||
* @param {number} featureIndex The index of the current element being processed in the | ||
* array.Starts at index 0, if an initialValue is provided, and at index 1 otherwise. | ||
* @param {Feature<any>} currentFeature The current Feature being processed. | ||
* @param {number} featureIndex The current index of the Feature being processed. | ||
*/ | ||
@@ -316,3 +320,3 @@ | ||
* @name featureEach | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON object | ||
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (currentFeature, featureIndex) | ||
@@ -358,4 +362,3 @@ * @example | ||
* @param {Feature} currentFeature The current Feature being processed. | ||
* @param {number} featureIndex The index of the current element being processed in the | ||
* array.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. | ||
*/ | ||
@@ -367,3 +370,3 @@ | ||
* @name featureReduce | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON object | ||
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (previousValue, currentFeature, featureIndex) | ||
@@ -388,4 +391,4 @@ * @param {*} [initialValue] Value to use as the first argument to the first call of the callback. | ||
featureEach(geojson, function (currentFeature, featureIndex) { | ||
if (featureIndex === 0 && initialValue === undefined) previousValue = currentFeature; | ||
else previousValue = callback(previousValue, currentFeature, featureIndex); | ||
if (featureIndex === 0 && initialValue === undefined) { previousValue = currentFeature; } | ||
else { previousValue = callback(previousValue, currentFeature, featureIndex); } | ||
}); | ||
@@ -399,3 +402,3 @@ return previousValue; | ||
* @name coordAll | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON object | ||
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object | ||
* @returns {Array<Array<number>>} coordinate position array | ||
@@ -423,8 +426,7 @@ * @example | ||
* @callback geomEachCallback | ||
* @param {Geometry} currentGeometry The current geometry being processed. | ||
* @param {number} featureIndex The index of the current element being processed in the | ||
* array. Starts at index 0, if an initialValue is provided, and at index 1 otherwise. | ||
* @param {Object} featureProperties The current feature properties being processed. | ||
* @param {Array<number>} featureBBox The current feature BBox being processed. | ||
* @param {number|string} featureId The current feature Id being processed. | ||
* @param {Geometry} currentGeometry The current Geometry being processed. | ||
* @param {number} featureIndex The current index of the Feature being processed. | ||
* @param {Object} featureProperties The current Feature Properties being processed. | ||
* @param {Array<number>} featureBBox The current Feature BBox being processed. | ||
* @param {number|string} featureId The current Feature Id being processed. | ||
*/ | ||
@@ -436,4 +438,4 @@ | ||
* @name geomEach | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (currentGeometry, featureIndex, currentProperties) | ||
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (currentGeometry, featureIndex, featureProperties, featureBBox, featureId) | ||
* @example | ||
@@ -445,6 +447,8 @@ * var features = turf.featureCollection([ | ||
* | ||
* turf.geomEach(features, function (currentGeometry, featureIndex, currentProperties) { | ||
* turf.geomEach(features, function (currentGeometry, featureIndex, featureProperties, featureBBox, featureId) { | ||
* //=currentGeometry | ||
* //=featureIndex | ||
* //=currentProperties | ||
* //=featureProperties | ||
* //=featureBBox | ||
* //=featureId | ||
* }); | ||
@@ -540,6 +544,7 @@ */ | ||
* of the callback, or initialValue, if supplied. | ||
* @param {Geometry} currentGeometry The current Feature being processed. | ||
* @param {number} currentIndex The index of the current element being processed in the | ||
* array.Starts at index 0, if an initialValue is provided, and at index 1 otherwise. | ||
* @param {Object} currentProperties The current feature properties being processed. | ||
* @param {Geometry} currentGeometry The current Geometry being processed. | ||
* @param {number} featureIndex The current index of the Feature being processed. | ||
* @param {Object} featureProperties The current Feature Properties being processed. | ||
* @param {Array<number>} featureBBox The current Feature BBox being processed. | ||
* @param {number|string} featureId The current Feature Id being processed. | ||
*/ | ||
@@ -551,4 +556,4 @@ | ||
* @name geomReduce | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (previousValue, currentGeometry, featureIndex, currentProperties) | ||
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId) | ||
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback. | ||
@@ -562,7 +567,9 @@ * @returns {*} The value that results from the reduction. | ||
* | ||
* turf.geomReduce(features, function (previousValue, currentGeometry, featureIndex, currentProperties) { | ||
* turf.geomReduce(features, function (previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId) { | ||
* //=previousValue | ||
* //=currentGeometry | ||
* //=featureIndex | ||
* //=currentProperties | ||
* //=featureProperties | ||
* //=featureBBox | ||
* //=featureId | ||
* return currentGeometry | ||
@@ -573,5 +580,5 @@ * }); | ||
var previousValue = initialValue; | ||
geomEach(geojson, function (currentGeometry, currentIndex, currentProperties) { | ||
if (currentIndex === 0 && initialValue === undefined) previousValue = currentGeometry; | ||
else previousValue = callback(previousValue, currentGeometry, currentIndex, currentProperties); | ||
geomEach(geojson, function (currentGeometry, featureIndex, featureProperties, featureBBox, featureId) { | ||
if (featureIndex === 0 && initialValue === undefined) { previousValue = currentGeometry; } | ||
else { previousValue = callback(previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId); } | ||
}); | ||
@@ -586,6 +593,4 @@ return previousValue; | ||
* @param {Feature} currentFeature The current flattened feature being processed. | ||
* @param {number} featureIndex The index of the current element being processed in the | ||
* array. Starts at index 0, if an initialValue is provided, and at index 1 otherwise. | ||
* @param {number} featureSubIndex The subindex of the current element being processed in the | ||
* array. Starts at index 0 and increases if the flattened feature was a multi-geometry. | ||
* @param {number} featureIndex The current index of the Feature being processed. | ||
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed. | ||
*/ | ||
@@ -598,4 +603,4 @@ | ||
* @name flattenEach | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (currentFeature, featureIndex, featureSubIndex) | ||
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (currentFeature, featureIndex, multiFeatureIndex) | ||
* @example | ||
@@ -607,6 +612,6 @@ * var features = turf.featureCollection([ | ||
* | ||
* turf.flattenEach(features, function (currentFeature, featureIndex, featureSubIndex) { | ||
* turf.flattenEach(features, function (currentFeature, featureIndex, multiFeatureIndex) { | ||
* //=currentFeature | ||
* //=featureIndex | ||
* //=featureSubIndex | ||
* //=multiFeatureIndex | ||
* }); | ||
@@ -623,3 +628,3 @@ */ | ||
case 'Polygon': | ||
callback(helpers.feature(geometry, properties, bbox, id), featureIndex, 0); | ||
callback(helpers.feature(geometry, properties, {bbox: bbox, id: id}), featureIndex, 0); | ||
return; | ||
@@ -643,3 +648,3 @@ } | ||
geometry.coordinates.forEach(function (coordinate, featureSubIndex) { | ||
geometry.coordinates.forEach(function (coordinate, multiFeatureIndex) { | ||
var geom = { | ||
@@ -649,3 +654,3 @@ type: geomType, | ||
}; | ||
callback(helpers.feature(geom, properties), featureIndex, featureSubIndex); | ||
callback(helpers.feature(geom, properties), featureIndex, multiFeatureIndex); | ||
}); | ||
@@ -674,6 +679,4 @@ | ||
* @param {Feature} currentFeature The current Feature being processed. | ||
* @param {number} featureIndex The index of the current element being processed in the | ||
* array.Starts at index 0, if an initialValue is provided, and at index 1 otherwise. | ||
* @param {number} featureSubIndex The subindex of the current element being processed in the | ||
* array. Starts at index 0 and increases if the flattened feature was a multi-geometry. | ||
* @param {number} featureIndex The current index of the Feature being processed. | ||
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed. | ||
*/ | ||
@@ -685,4 +688,4 @@ | ||
* @name flattenReduce | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (previousValue, currentFeature, featureIndex, featureSubIndex) | ||
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (previousValue, currentFeature, featureIndex, multiFeatureIndex) | ||
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback. | ||
@@ -696,7 +699,7 @@ * @returns {*} The value that results from the reduction. | ||
* | ||
* turf.flattenReduce(features, function (previousValue, currentFeature, featureIndex, featureSubIndex) { | ||
* turf.flattenReduce(features, function (previousValue, currentFeature, featureIndex, multiFeatureIndex) { | ||
* //=previousValue | ||
* //=currentFeature | ||
* //=featureIndex | ||
* //=featureSubIndex | ||
* //=multiFeatureIndex | ||
* return currentFeature | ||
@@ -707,5 +710,5 @@ * }); | ||
var previousValue = initialValue; | ||
flattenEach(geojson, function (currentFeature, featureIndex, featureSubIndex) { | ||
if (featureIndex === 0 && featureSubIndex === 0 && initialValue === undefined) previousValue = currentFeature; | ||
else previousValue = callback(previousValue, currentFeature, featureIndex, featureSubIndex); | ||
flattenEach(geojson, function (currentFeature, featureIndex, multiFeatureIndex) { | ||
if (featureIndex === 0 && multiFeatureIndex === 0 && initialValue === undefined) { previousValue = currentFeature; } | ||
else { previousValue = callback(previousValue, currentFeature, featureIndex, multiFeatureIndex); } | ||
}); | ||
@@ -719,6 +722,7 @@ return previousValue; | ||
* @callback segmentEachCallback | ||
* @param {Feature<LineString>} currentSegment The current segment being processed. | ||
* @param {number} featureIndex The featureIndex currently being processed, starts at index 0. | ||
* @param {number} featureSubIndex The featureSubIndex currently being processed, starts at index 0. | ||
* @param {number} segmentIndex The segmentIndex currently being processed, starts at index 0. | ||
* @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} | ||
@@ -731,4 +735,4 @@ */ | ||
* | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON | ||
* @param {Function} callback a method that takes (currentSegment, featureIndex, featureSubIndex) | ||
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON | ||
* @param {Function} callback a method that takes (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) | ||
* @returns {void} | ||
@@ -739,7 +743,8 @@ * @example | ||
* // Iterate over GeoJSON by 2-vertex segments | ||
* turf.segmentEach(polygon, function (currentSegment, featureIndex, featureSubIndex, segmentIndex) { | ||
* //= currentSegment | ||
* //= featureIndex | ||
* //= featureSubIndex | ||
* //= segmentIndex | ||
* turf.segmentEach(polygon, function (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) { | ||
* //=currentSegment | ||
* //=featureIndex | ||
* //=multiFeatureIndex | ||
* //=geometryIndex | ||
* //=segmentIndex | ||
* }); | ||
@@ -754,15 +759,15 @@ * | ||
function segmentEach(geojson, callback) { | ||
flattenEach(geojson, function (feature$$1, featureIndex, featureSubIndex) { | ||
flattenEach(geojson, function (feature$$1, featureIndex, multiFeatureIndex) { | ||
var segmentIndex = 0; | ||
// Exclude null Geometries | ||
if (!feature$$1.geometry) return; | ||
if (!feature$$1.geometry) { return; } | ||
// (Multi)Point geometries do not contain segments therefore they are ignored during this operation. | ||
var type = feature$$1.geometry.type; | ||
if (type === 'Point' || type === 'MultiPoint') return; | ||
if (type === 'Point' || type === 'MultiPoint') { return; } | ||
// Generate 2-vertex line segments | ||
coordReduce(feature$$1, function (previousCoords, currentCoord) { | ||
coordReduce(feature$$1, function (previousCoords, currentCoord, coordIndex, featureIndexCoord, mutliPartIndexCoord, geometryIndex) { | ||
var currentSegment = helpers.lineString([previousCoords, currentCoord], feature$$1.properties); | ||
callback(currentSegment, featureIndex, featureSubIndex, segmentIndex); | ||
callback(currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex); | ||
segmentIndex++; | ||
@@ -789,8 +794,9 @@ return currentCoord; | ||
* @callback segmentReduceCallback | ||
* @param {*} [previousValue] The accumulated value previously returned in the last invocation | ||
* @param {*} 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 featureIndex currently being processed, starts at index 0. | ||
* @param {number} featureSubIndex The featureSubIndex currently being processed, starts at index 0. | ||
* @param {number} segmentIndex The segmentIndex currently being processed, starts at index 0. | ||
* @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. | ||
*/ | ||
@@ -802,3 +808,3 @@ | ||
* | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON | ||
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON | ||
* @param {Function} callback a method that takes (previousValue, currentSegment, currentIndex) | ||
@@ -811,7 +817,8 @@ * @param {*} [initialValue] Value to use as the first argument to the first call of the callback. | ||
* // Iterate over GeoJSON by 2-vertex segments | ||
* turf.segmentReduce(polygon, function (previousSegment, currentSegment, featureIndex, featureSubIndex, segmentIndex) { | ||
* turf.segmentReduce(polygon, function (previousSegment, currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) { | ||
* //= previousSegment | ||
* //= currentSegment | ||
* //= featureIndex | ||
* //= featureSubIndex | ||
* //= multiFeatureIndex | ||
* //= geometryIndex | ||
* //= segmentInex | ||
@@ -831,5 +838,5 @@ * return currentSegment | ||
var started = false; | ||
segmentEach(geojson, function (currentSegment, featureIndex, featureSubIndex, segmentIndex) { | ||
if (started === false && initialValue === undefined) previousValue = currentSegment; | ||
else previousValue = callback(previousValue, currentSegment, featureIndex, featureSubIndex, segmentIndex); | ||
segmentEach(geojson, function (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) { | ||
if (started === false && initialValue === undefined) { previousValue = currentSegment; } | ||
else { previousValue = callback(previousValue, currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex); } | ||
started = true; | ||
@@ -844,6 +851,6 @@ }); | ||
* @callback lineEachCallback | ||
* @param {Feature<LineString>} currentLine The current LineString|LinearRing being processed. | ||
* @param {number} featureIndex The feature index of the current element being processed in the array, starts at index 0. | ||
* @param {number} featureSubIndex The feature sub-index of the current line being processed at index 0 | ||
* @param {number} lineIndex The current line being processed at index 0 | ||
* @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 | ||
*/ | ||
@@ -857,3 +864,3 @@ | ||
* @param {Geometry|Feature<LineString|Polygon|MultiLineString|MultiPolygon>} geojson object | ||
* @param {Function} callback a method that takes (currentLine, featureIndex, featureSubIndex, lineIndex) | ||
* @param {Function} callback a method that takes (currentLine, featureIndex, multiFeatureIndex, geometryIndex) | ||
* @example | ||
@@ -865,7 +872,7 @@ * var multiLine = turf.multiLineString([ | ||
* | ||
* turf.lineEach(multiLine, function (currentLine, featureIndex, featureSubIndex, lineIndex) { | ||
* turf.lineEach(multiLine, function (currentLine, featureIndex, multiFeatureIndex, geometryIndex) { | ||
* //=currentLine | ||
* //=featureIndex | ||
* //=featureSubIndex | ||
* //=lineIndex | ||
* //=multiFeatureIndex | ||
* //=geometryIndex | ||
* }); | ||
@@ -875,6 +882,6 @@ */ | ||
// validation | ||
if (!geojson) throw new Error('geojson is required'); | ||
if (!geojson) { throw new Error('geojson is required'); } | ||
flattenEach(geojson, function (feature$$1, featureIndex, featureSubIndex) { | ||
if (feature$$1.geometry === null) return; | ||
flattenEach(geojson, function (feature$$1, featureIndex, multiFeatureIndex) { | ||
if (feature$$1.geometry === null) { return; } | ||
var type = feature$$1.geometry.type; | ||
@@ -884,7 +891,7 @@ var coords = feature$$1.geometry.coordinates; | ||
case 'LineString': | ||
callback(feature$$1, featureIndex, featureSubIndex, 0); | ||
callback(feature$$1, featureIndex, multiFeatureIndex, 0, 0); | ||
break; | ||
case 'Polygon': | ||
for (var lineIndex = 0; lineIndex < coords.length; lineIndex++) { | ||
callback(helpers.lineString(coords[lineIndex], feature$$1.properties), featureIndex, featureSubIndex, lineIndex); | ||
for (var geometryIndex = 0; geometryIndex < coords.length; geometryIndex++) { | ||
callback(helpers.lineString(coords[geometryIndex], feature$$1.properties), featureIndex, multiFeatureIndex, geometryIndex); | ||
} | ||
@@ -914,5 +921,5 @@ break; | ||
* @param {Feature<LineString>} currentLine The current LineString|LinearRing being processed. | ||
* @param {number} featureIndex The feature index of the current element being processed in the array, starts at index 0. | ||
* @param {number} featureSubIndex The feature sub-index of the current line being processed at index 0 | ||
* @param {number} lineIndex The current line being processed at index 0 | ||
* @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 | ||
*/ | ||
@@ -925,7 +932,7 @@ | ||
* @param {Geometry|Feature<LineString|Polygon|MultiLineString|MultiPolygon>} geojson object | ||
* @param {Function} callback a method that takes (previousValue, currentFeature, featureIndex) | ||
* @param {Function} callback a method that takes (previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex) | ||
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback. | ||
* @returns {*} The value that results from the reduction. | ||
* @example | ||
* var mtp = turf.multiPolygon([ | ||
* var multiPoly = turf.multiPolygon([ | ||
* turf.polygon([[[12,48],[2,41],[24,38],[12,48]], [[9,44],[13,41],[13,45],[9,44]]]), | ||
@@ -935,16 +942,16 @@ * turf.polygon([[[5, 5], [0, 0], [2, 2], [4, 4], [5, 5]]]) | ||
* | ||
* turf.lineReduce(mtp, function (previousValue, currentLine, featureIndex, featureSubIndex, lineIndex) { | ||
* turf.lineReduce(multiPoly, function (previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex) { | ||
* //=previousValue | ||
* //=currentLine | ||
* //=featureIndex | ||
* //=featureSubIndex | ||
* //=lineIndex | ||
* //=multiFeatureIndex | ||
* //=geometryIndex | ||
* return currentLine | ||
* }, 2); | ||
* }); | ||
*/ | ||
function lineReduce(geojson, callback, initialValue) { | ||
var previousValue = initialValue; | ||
lineEach(geojson, function (currentLine, featureIndex, featureSubIndex, lineIndex) { | ||
if (featureIndex === 0 && initialValue === undefined) previousValue = currentLine; | ||
else previousValue = callback(previousValue, currentLine, featureIndex, featureSubIndex, lineIndex); | ||
lineEach(geojson, function (currentLine, featureIndex, multiFeatureIndex, geometryIndex) { | ||
if (featureIndex === 0 && initialValue === undefined) { previousValue = currentLine; } | ||
else { previousValue = callback(previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex); } | ||
}); | ||
@@ -951,0 +958,0 @@ return previousValue; |
{ | ||
"name": "@turf/meta", | ||
"version": "5.0.4", | ||
"version": "5.1.0", | ||
"description": "turf meta module", | ||
"main": "main", | ||
"module": "index", | ||
"jsnext:main": "index", | ||
"main": "main.js", | ||
"module": "main.mjs", | ||
"types": "index.d.ts", | ||
@@ -12,3 +11,4 @@ "files": [ | ||
"index.d.ts", | ||
"main.js" | ||
"main.js", | ||
"main.mjs" | ||
], | ||
@@ -18,3 +18,4 @@ "scripts": { | ||
"test": "node -r @std/esm test.js", | ||
"bench": "node -r @std/esm bench.js" | ||
"bench": "node -r @std/esm bench.js", | ||
"docs": "node ../../scripts/generate-readmes" | ||
}, | ||
@@ -60,9 +61,10 @@ "repository": { | ||
"@std/esm": "*", | ||
"@turf/random": "^5.0.4", | ||
"@turf/random": "^5.1.0", | ||
"benchmark": "*", | ||
"rollup": "*", | ||
"rollup-plugin-buble": "*", | ||
"tape": "*" | ||
}, | ||
"dependencies": { | ||
"@turf/helpers": "^5.0.4" | ||
"@turf/helpers": "^5.1.0" | ||
}, | ||
@@ -69,0 +71,0 @@ "@std/esm": { |
211
README.md
@@ -15,5 +15,5 @@ # @turf/meta | ||
- `coordIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the coordinate being processed. | ||
Starts at index 0. | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the feature being processed. | ||
- `featureSubIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current subIndex of the feature being processed. | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Feature being processed. | ||
- `multiFeatureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Multi-Feature being processed. | ||
- `geometryIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Geometry being processed. | ||
@@ -26,4 +26,4 @@ ## coordEach | ||
- `geojson` **([FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects) \| [Geometry](http://geojson.org/geojson-spec.html#geometry))** any GeoJSON object | ||
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** a method that takes (currentCoord, coordIndex, featureIndex, featureSubIndex) | ||
- `geojson` **([FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3) \| [Feature](https://tools.ietf.org/html/rfc7946#section-3.2) \| [Geometry](https://tools.ietf.org/html/rfc7946#section-3.1))** any GeoJSON object | ||
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** a method that takes (currentCoord, coordIndex, featureIndex, multiFeatureIndex) | ||
- `excludeWrapCoord` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration. (optional, default `false`) | ||
@@ -39,7 +39,8 @@ | ||
turf.coordEach(features, function (currentCoord, coordIndex, featureIndex, featureSubIndex) { | ||
turf.coordEach(features, function (currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) { | ||
//=currentCoord | ||
//=coordIndex | ||
//=featureIndex | ||
//=featureSubIndex | ||
//=multiFeatureIndex | ||
//=geometryIndex | ||
}); | ||
@@ -54,3 +55,3 @@ ``` | ||
- `geojson` **([FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) \| [Geometry](http://geojson.org/geojson-spec.html#geometry) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects))** any GeoJSON object | ||
- `geojson` **([FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3) \| [Geometry](https://tools.ietf.org/html/rfc7946#section-3.1) \| [Feature](https://tools.ietf.org/html/rfc7946#section-3.2))** any GeoJSON object | ||
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** a method that takes (previousValue, currentCoord, coordIndex) | ||
@@ -68,3 +69,3 @@ - `initialValue` **any?** Value to use as the first argument to the first call of the callback. | ||
turf.coordReduce(features, function (previousValue, currentCoord, coordIndex, featureIndex, featureSubIndex) { | ||
turf.coordReduce(features, function (previousValue, currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) { | ||
//=previousValue | ||
@@ -74,3 +75,4 @@ //=currentCoord | ||
//=featureIndex | ||
//=featureSubIndex | ||
//=multiFeatureIndex | ||
//=geometryIndex | ||
return currentCoord; | ||
@@ -108,4 +110,5 @@ }); | ||
Starts at index 0, if an initialValue is provided, and at index 1 otherwise. | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the feature being processed. | ||
- `featureSubIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current subIndex of the feature being processed. | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Feature being processed. | ||
- `multiFeatureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Multi-Feature being processed. | ||
- `geometryIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Geometry being processed. | ||
@@ -118,3 +121,3 @@ ## propEach | ||
- `geojson` **([FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects))** any GeoJSON object | ||
- `geojson` **([FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3) \| [Feature](https://tools.ietf.org/html/rfc7946#section-3.2))** any GeoJSON object | ||
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** a method that takes (currentProperties, featureIndex) | ||
@@ -144,5 +147,4 @@ | ||
- `currentProperties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** The current properties being processed. | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The index of the current element being processed in the | ||
array.Starts at index 0, if an initialValue is provided, and at index 1 otherwise. | ||
- `currentProperties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** The current Properties being processed. | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Feature being processed. | ||
@@ -157,3 +159,3 @@ ## propReduce | ||
- `geojson` **([FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects))** any GeoJSON object | ||
- `geojson` **([FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3) \| [Feature](https://tools.ietf.org/html/rfc7946#section-3.2))** any GeoJSON object | ||
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** a method that takes (previousValue, currentProperties, featureIndex) | ||
@@ -203,5 +205,4 @@ - `initialValue` **any?** Value to use as the first argument to the first call of the callback. | ||
of the callback, or initialValue, if supplied. | ||
- `currentProperties` **any** The current properties being processed. | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The index of the current element being processed in the | ||
array.Starts at index 0, if an initialValue is provided, and at index 1 otherwise. | ||
- `currentProperties` **any** The current Properties being processed. | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Feature being processed. | ||
@@ -215,3 +216,3 @@ ## featureEach | ||
- `geojson` **([FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects) \| [Geometry](http://geojson.org/geojson-spec.html#geometry))** any GeoJSON object | ||
- `geojson` **([FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3) \| [Feature](https://tools.ietf.org/html/rfc7946#section-3.2) \| [Geometry](https://tools.ietf.org/html/rfc7946#section-3.1))** any GeoJSON object | ||
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** a method that takes (currentFeature, featureIndex) | ||
@@ -241,5 +242,4 @@ | ||
- `currentFeature` **[Feature](http://geojson.org/geojson-spec.html#feature-objects)<any>** The current feature being processed. | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The index of the current element being processed in the | ||
array.Starts at index 0, if an initialValue is provided, and at index 1 otherwise. | ||
- `currentFeature` **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)<any>** The current Feature being processed. | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Feature being processed. | ||
@@ -269,5 +269,4 @@ ## featureReduceCallback | ||
of the callback, or initialValue, if supplied. | ||
- `currentFeature` **[Feature](http://geojson.org/geojson-spec.html#feature-objects)** The current Feature being processed. | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The index of the current element being processed in the | ||
array.Starts at index 0, if an initialValue is provided, and at index 1 otherwise. | ||
- `currentFeature` **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)** The current Feature being processed. | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Feature being processed. | ||
@@ -280,3 +279,3 @@ ## featureReduce | ||
- `geojson` **([FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects) \| [Geometry](http://geojson.org/geojson-spec.html#geometry))** any GeoJSON object | ||
- `geojson` **([FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3) \| [Feature](https://tools.ietf.org/html/rfc7946#section-3.2) \| [Geometry](https://tools.ietf.org/html/rfc7946#section-3.1))** any GeoJSON object | ||
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** a method that takes (previousValue, currentFeature, featureIndex) | ||
@@ -309,3 +308,3 @@ - `initialValue` **any?** Value to use as the first argument to the first call of the callback. | ||
- `geojson` **([FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects) \| [Geometry](http://geojson.org/geojson-spec.html#geometry))** any GeoJSON object | ||
- `geojson` **([FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3) \| [Feature](https://tools.ietf.org/html/rfc7946#section-3.2) \| [Geometry](https://tools.ietf.org/html/rfc7946#section-3.1))** any GeoJSON object | ||
@@ -334,8 +333,7 @@ **Examples** | ||
- `currentGeometry` **[Geometry](http://geojson.org/geojson-spec.html#geometry)** The current geometry being processed. | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The index of the current element being processed in the | ||
array. Starts at index 0, if an initialValue is provided, and at index 1 otherwise. | ||
- `featureProperties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** The current feature properties being processed. | ||
- `featureBBox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** The current feature BBox being processed. | ||
- `featureId` **([number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) \| [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String))** The current feature Id being processed. | ||
- `currentGeometry` **[Geometry](https://tools.ietf.org/html/rfc7946#section-3.1)** The current Geometry being processed. | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Feature being processed. | ||
- `featureProperties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** The current Feature Properties being processed. | ||
- `featureBBox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** The current Feature BBox being processed. | ||
- `featureId` **([number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) \| [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String))** The current Feature Id being processed. | ||
@@ -348,4 +346,4 @@ ## geomEach | ||
- `geojson` **([FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects) \| [Geometry](http://geojson.org/geojson-spec.html#geometry))** any GeoJSON object | ||
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** a method that takes (currentGeometry, featureIndex, currentProperties) | ||
- `geojson` **([FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3) \| [Feature](https://tools.ietf.org/html/rfc7946#section-3.2) \| [Geometry](https://tools.ietf.org/html/rfc7946#section-3.1))** any GeoJSON object | ||
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** a method that takes (currentGeometry, featureIndex, featureProperties, featureBBox, featureId) | ||
@@ -360,6 +358,8 @@ **Examples** | ||
turf.geomEach(features, function (currentGeometry, featureIndex, currentProperties) { | ||
turf.geomEach(features, function (currentGeometry, featureIndex, featureProperties, featureBBox, featureId) { | ||
//=currentGeometry | ||
//=featureIndex | ||
//=currentProperties | ||
//=featureProperties | ||
//=featureBBox | ||
//=featureId | ||
}); | ||
@@ -391,6 +391,7 @@ ``` | ||
of the callback, or initialValue, if supplied. | ||
- `currentGeometry` **[Geometry](http://geojson.org/geojson-spec.html#geometry)** The current Feature being processed. | ||
- `currentIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The index of the current element being processed in the | ||
array.Starts at index 0, if an initialValue is provided, and at index 1 otherwise. | ||
- `currentProperties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** The current feature properties being processed. | ||
- `currentGeometry` **[Geometry](https://tools.ietf.org/html/rfc7946#section-3.1)** The current Geometry being processed. | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Feature being processed. | ||
- `featureProperties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** The current Feature Properties being processed. | ||
- `featureBBox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** The current Feature BBox being processed. | ||
- `featureId` **([number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) \| [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String))** The current Feature Id being processed. | ||
@@ -403,4 +404,4 @@ ## geomReduce | ||
- `geojson` **([FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects) \| [Geometry](http://geojson.org/geojson-spec.html#geometry))** any GeoJSON object | ||
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** a method that takes (previousValue, currentGeometry, featureIndex, currentProperties) | ||
- `geojson` **([FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3) \| [Feature](https://tools.ietf.org/html/rfc7946#section-3.2) \| [Geometry](https://tools.ietf.org/html/rfc7946#section-3.1))** any GeoJSON object | ||
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** a method that takes (previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId) | ||
- `initialValue` **any?** Value to use as the first argument to the first call of the callback. | ||
@@ -416,7 +417,9 @@ | ||
turf.geomReduce(features, function (previousValue, currentGeometry, featureIndex, currentProperties) { | ||
turf.geomReduce(features, function (previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId) { | ||
//=previousValue | ||
//=currentGeometry | ||
//=featureIndex | ||
//=currentProperties | ||
//=featureProperties | ||
//=featureBBox | ||
//=featureId | ||
return currentGeometry | ||
@@ -436,7 +439,5 @@ }); | ||
- `currentFeature` **[Feature](http://geojson.org/geojson-spec.html#feature-objects)** The current flattened feature being processed. | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The index of the current element being processed in the | ||
array. Starts at index 0, if an initialValue is provided, and at index 1 otherwise. | ||
- `featureSubIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The subindex of the current element being processed in the | ||
array. Starts at index 0 and increases if the flattened feature was a multi-geometry. | ||
- `currentFeature` **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)** The current flattened feature being processed. | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Feature being processed. | ||
- `multiFeatureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Multi-Feature being processed. | ||
@@ -450,4 +451,4 @@ ## flattenEach | ||
- `geojson` **([FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects) \| [Geometry](http://geojson.org/geojson-spec.html#geometry))** any GeoJSON object | ||
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** a method that takes (currentFeature, featureIndex, featureSubIndex) | ||
- `geojson` **([FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3) \| [Feature](https://tools.ietf.org/html/rfc7946#section-3.2) \| [Geometry](https://tools.ietf.org/html/rfc7946#section-3.1))** any GeoJSON object | ||
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** a method that takes (currentFeature, featureIndex, multiFeatureIndex) | ||
@@ -462,6 +463,6 @@ **Examples** | ||
turf.flattenEach(features, function (currentFeature, featureIndex, featureSubIndex) { | ||
turf.flattenEach(features, function (currentFeature, featureIndex, multiFeatureIndex) { | ||
//=currentFeature | ||
//=featureIndex | ||
//=featureSubIndex | ||
//=multiFeatureIndex | ||
}); | ||
@@ -493,7 +494,5 @@ ``` | ||
of the callback, or initialValue, if supplied. | ||
- `currentFeature` **[Feature](http://geojson.org/geojson-spec.html#feature-objects)** The current Feature being processed. | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The index of the current element being processed in the | ||
array.Starts at index 0, if an initialValue is provided, and at index 1 otherwise. | ||
- `featureSubIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The subindex of the current element being processed in the | ||
array. Starts at index 0 and increases if the flattened feature was a multi-geometry. | ||
- `currentFeature` **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)** The current Feature being processed. | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Feature being processed. | ||
- `multiFeatureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Multi-Feature being processed. | ||
@@ -506,4 +505,4 @@ ## flattenReduce | ||
- `geojson` **([FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects) \| [Geometry](http://geojson.org/geojson-spec.html#geometry))** any GeoJSON object | ||
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** a method that takes (previousValue, currentFeature, featureIndex, featureSubIndex) | ||
- `geojson` **([FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3) \| [Feature](https://tools.ietf.org/html/rfc7946#section-3.2) \| [Geometry](https://tools.ietf.org/html/rfc7946#section-3.1))** any GeoJSON object | ||
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** a method that takes (previousValue, currentFeature, featureIndex, multiFeatureIndex) | ||
- `initialValue` **any?** Value to use as the first argument to the first call of the callback. | ||
@@ -519,7 +518,7 @@ | ||
turf.flattenReduce(features, function (previousValue, currentFeature, featureIndex, featureSubIndex) { | ||
turf.flattenReduce(features, function (previousValue, currentFeature, featureIndex, multiFeatureIndex) { | ||
//=previousValue | ||
//=currentFeature | ||
//=featureIndex | ||
//=featureSubIndex | ||
//=multiFeatureIndex | ||
return currentFeature | ||
@@ -539,6 +538,7 @@ }); | ||
- `currentSegment` **[Feature](http://geojson.org/geojson-spec.html#feature-objects)<[LineString](http://geojson.org/geojson-spec.html#linestring)>** The current segment being processed. | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The featureIndex currently being processed, starts at index 0. | ||
- `featureSubIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The featureSubIndex currently being processed, starts at index 0. | ||
- `segmentIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The segmentIndex currently being processed, starts at index 0. | ||
- `currentSegment` **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)<[LineString](https://tools.ietf.org/html/rfc7946#section-3.1.4)>** The current Segment being processed. | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Feature being processed. | ||
- `multiFeatureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Multi-Feature being processed. | ||
- `geometryIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Geometry being processed. | ||
- `segmentIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Segment being processed. | ||
@@ -554,4 +554,4 @@ Returns **void** | ||
- `geojson` **([FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects) \| [Geometry](http://geojson.org/geojson-spec.html#geometry))** any GeoJSON | ||
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** a method that takes (currentSegment, featureIndex, featureSubIndex) | ||
- `geojson` **([FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3) \| [Feature](https://tools.ietf.org/html/rfc7946#section-3.2) \| [Geometry](https://tools.ietf.org/html/rfc7946#section-3.1))** any GeoJSON | ||
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** a method that takes (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) | ||
@@ -564,7 +564,8 @@ **Examples** | ||
// Iterate over GeoJSON by 2-vertex segments | ||
turf.segmentEach(polygon, function (currentSegment, featureIndex, featureSubIndex, segmentIndex) { | ||
//= currentSegment | ||
//= featureIndex | ||
//= featureSubIndex | ||
//= segmentIndex | ||
turf.segmentEach(polygon, function (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) { | ||
//=currentSegment | ||
//=featureIndex | ||
//=multiFeatureIndex | ||
//=geometryIndex | ||
//=segmentIndex | ||
}); | ||
@@ -602,8 +603,9 @@ | ||
- `previousValue` **any?** The accumulated value previously returned in the last invocation | ||
- `previousValue` **any** The accumulated value previously returned in the last invocation | ||
of the callback, or initialValue, if supplied. | ||
- `currentSegment` **[Feature](http://geojson.org/geojson-spec.html#feature-objects)<[LineString](http://geojson.org/geojson-spec.html#linestring)>?** The current segment being processed. | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The featureIndex currently being processed, starts at index 0. | ||
- `featureSubIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The featureSubIndex currently being processed, starts at index 0. | ||
- `segmentIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The segmentIndex currently being processed, starts at index 0. | ||
- `currentSegment` **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)<[LineString](https://tools.ietf.org/html/rfc7946#section-3.1.4)>** The current Segment being processed. | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Feature being processed. | ||
- `multiFeatureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Multi-Feature being processed. | ||
- `geometryIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Geometry being processed. | ||
- `segmentIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Segment being processed. | ||
@@ -617,3 +619,3 @@ ## segmentReduce | ||
- `geojson` **([FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects) \| [Geometry](http://geojson.org/geojson-spec.html#geometry))** any GeoJSON | ||
- `geojson` **([FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3) \| [Feature](https://tools.ietf.org/html/rfc7946#section-3.2) \| [Geometry](https://tools.ietf.org/html/rfc7946#section-3.1))** any GeoJSON | ||
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** a method that takes (previousValue, currentSegment, currentIndex) | ||
@@ -628,7 +630,8 @@ - `initialValue` **any?** Value to use as the first argument to the first call of the callback. | ||
// Iterate over GeoJSON by 2-vertex segments | ||
turf.segmentReduce(polygon, function (previousSegment, currentSegment, featureIndex, featureSubIndex, segmentIndex) { | ||
turf.segmentReduce(polygon, function (previousSegment, currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) { | ||
//= previousSegment | ||
//= currentSegment | ||
//= featureIndex | ||
//= featureSubIndex | ||
//= multiFeatureIndex | ||
//= geometryIndex | ||
//= segmentInex | ||
@@ -656,6 +659,6 @@ return currentSegment | ||
- `currentLine` **[Feature](http://geojson.org/geojson-spec.html#feature-objects)<[LineString](http://geojson.org/geojson-spec.html#linestring)>** The current LineString|LinearRing being processed. | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The feature index of the current element being processed in the array, starts at index 0. | ||
- `featureSubIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The feature sub-index of the current line being processed at index 0 | ||
- `lineIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current line being processed at index 0 | ||
- `currentLine` **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)<[LineString](https://tools.ietf.org/html/rfc7946#section-3.1.4)>** The current LineString|LinearRing being processed | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Feature being processed | ||
- `multiFeatureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Multi-Feature being processed | ||
- `geometryIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Geometry being processed | ||
@@ -669,4 +672,4 @@ ## lineEach | ||
- `geojson` **([Geometry](http://geojson.org/geojson-spec.html#geometry) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects)<([LineString](http://geojson.org/geojson-spec.html#linestring) \| [Polygon](http://geojson.org/geojson-spec.html#polygon) \| [MultiLineString](http://geojson.org/geojson-spec.html#multilinestring) \| [MultiPolygon](http://geojson.org/geojson-spec.html#multipolygon))>)** object | ||
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** a method that takes (currentLine, featureIndex, featureSubIndex, lineIndex) | ||
- `geojson` **([Geometry](https://tools.ietf.org/html/rfc7946#section-3.1) \| [Feature](https://tools.ietf.org/html/rfc7946#section-3.2)<([LineString](https://tools.ietf.org/html/rfc7946#section-3.1.4) \| [Polygon](https://tools.ietf.org/html/rfc7946#section-3.1.6) \| [MultiLineString](https://tools.ietf.org/html/rfc7946#section-3.1.5) \| [MultiPolygon](https://tools.ietf.org/html/rfc7946#section-3.1.7))>)** object | ||
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** a method that takes (currentLine, featureIndex, multiFeatureIndex, geometryIndex) | ||
@@ -681,7 +684,7 @@ **Examples** | ||
turf.lineEach(multiLine, function (currentLine, featureIndex, featureSubIndex, lineIndex) { | ||
turf.lineEach(multiLine, function (currentLine, featureIndex, multiFeatureIndex, geometryIndex) { | ||
//=currentLine | ||
//=featureIndex | ||
//=featureSubIndex | ||
//=lineIndex | ||
//=multiFeatureIndex | ||
//=geometryIndex | ||
}); | ||
@@ -713,6 +716,6 @@ ``` | ||
of the callback, or initialValue, if supplied. | ||
- `currentLine` **[Feature](http://geojson.org/geojson-spec.html#feature-objects)<[LineString](http://geojson.org/geojson-spec.html#linestring)>** The current LineString|LinearRing being processed. | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The feature index of the current element being processed in the array, starts at index 0. | ||
- `featureSubIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The feature sub-index of the current line being processed at index 0 | ||
- `lineIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current line being processed at index 0 | ||
- `currentLine` **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)<[LineString](https://tools.ietf.org/html/rfc7946#section-3.1.4)>** The current LineString|LinearRing being processed. | ||
- `featureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Feature being processed | ||
- `multiFeatureIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Multi-Feature being processed | ||
- `geometryIndex` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** The current index of the Geometry being processed | ||
@@ -725,4 +728,4 @@ ## lineReduce | ||
- `geojson` **([Geometry](http://geojson.org/geojson-spec.html#geometry) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects)<([LineString](http://geojson.org/geojson-spec.html#linestring) \| [Polygon](http://geojson.org/geojson-spec.html#polygon) \| [MultiLineString](http://geojson.org/geojson-spec.html#multilinestring) \| [MultiPolygon](http://geojson.org/geojson-spec.html#multipolygon))>)** object | ||
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** a method that takes (previousValue, currentFeature, featureIndex) | ||
- `geojson` **([Geometry](https://tools.ietf.org/html/rfc7946#section-3.1) \| [Feature](https://tools.ietf.org/html/rfc7946#section-3.2)<([LineString](https://tools.ietf.org/html/rfc7946#section-3.1.4) \| [Polygon](https://tools.ietf.org/html/rfc7946#section-3.1.6) \| [MultiLineString](https://tools.ietf.org/html/rfc7946#section-3.1.5) \| [MultiPolygon](https://tools.ietf.org/html/rfc7946#section-3.1.7))>)** object | ||
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** a method that takes (previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex) | ||
- `initialValue` **any?** Value to use as the first argument to the first call of the callback. | ||
@@ -733,3 +736,3 @@ | ||
```javascript | ||
var mtp = turf.multiPolygon([ | ||
var multiPoly = turf.multiPolygon([ | ||
turf.polygon([[[12,48],[2,41],[24,38],[12,48]], [[9,44],[13,41],[13,45],[9,44]]]), | ||
@@ -739,10 +742,10 @@ turf.polygon([[[5, 5], [0, 0], [2, 2], [4, 4], [5, 5]]]) | ||
turf.lineReduce(mtp, function (previousValue, currentLine, featureIndex, featureSubIndex, lineIndex) { | ||
turf.lineReduce(multiPoly, function (previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex) { | ||
//=previousValue | ||
//=currentLine | ||
//=featureIndex | ||
//=featureSubIndex | ||
//=lineIndex | ||
//=multiFeatureIndex | ||
//=geometryIndex | ||
return currentLine | ||
}, 2); | ||
}); | ||
``` | ||
@@ -749,0 +752,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
153104
7
2743
738
6
Updated@turf/helpers@^5.1.0