Package Exports
- @turf/meta
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@turf/meta) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@turf/meta
coordEachCallback
Callback for coordEach
Type: Function
Parameters
currentCoordArray<number> The current coordinate being processed.coordIndexnumber The current index of the coordinate being processed. Starts at index 0.featureIndexnumber The current index of the feature being processed.featureSubIndexnumber The current subIndex of the feature being processed.
coordEach
Iterate over coordinates in any GeoJSON object, similar to Array.forEach()
Parameters
geojson(FeatureCollection | Feature | Geometry) any GeoJSON objectcallbackFunction a method that takes (currentCoord, coordIndex, featureIndex, featureSubIndex)excludeWrapCoordboolean whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration. (optional, defaultfalse)
Examples
var features = turf.featureCollection([
turf.point([26, 37], {"foo": "bar"}),
turf.point([36, 53], {"hello": "world"})
]);
turf.coordEach(features, function (currentCoord, coordIndex, featureIndex, featureSubIndex) {
//=currentCoord
//=coordIndex
//=featureIndex
//=featureSubIndex
});coordReduce
Reduce coordinates in any GeoJSON object, similar to Array.reduce()
Parameters
geojson(FeatureCollection | Geometry | Feature) any GeoJSON objectcallbackFunction a method that takes (previousValue, currentCoord, coordIndex)initialValueany? Value to use as the first argument to the first call of the callback.excludeWrapCoordboolean whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration. (optional, defaultfalse)
Examples
var features = turf.featureCollection([
turf.point([26, 37], {"foo": "bar"}),
turf.point([36, 53], {"hello": "world"})
]);
turf.coordReduce(features, function (previousValue, currentCoord, coordIndex, featureIndex, featureSubIndex) {
//=previousValue
//=currentCoord
//=coordIndex
//=featureIndex
//=featureSubIndex
return currentCoord;
});Returns any The value that results from the reduction.
coordReduceCallback
Callback for coordReduce
The first time the callback function is called, the values provided as arguments depend on whether the reduce method has an initialValue argument.
If an initialValue is provided to the reduce method:
- The previousValue argument is initialValue.
- The currentValue argument is the value of the first element present in the array.
If an initialValue is not provided:
- The previousValue argument is the value of the first element present in the array.
- The currentValue argument is the value of the second element present in the array.
Type: Function
Parameters
previousValueany The accumulated value previously returned in the last invocation of the callback, or initialValue, if supplied.currentCoordArray<number> The current coordinate being processed.coordIndexnumber The current index of the coordinate being processed. Starts at index 0, if an initialValue is provided, and at index 1 otherwise.featureIndexnumber The current index of the feature being processed.featureSubIndexnumber The current subIndex of the feature being processed.
propEach
Iterate over properties in any GeoJSON object, similar to Array.forEach()
Parameters
geojson(FeatureCollection | Feature) any GeoJSON objectcallbackFunction a method that takes (currentProperties, featureIndex)
Examples
var features = turf.featureCollection([
turf.point([26, 37], {foo: 'bar'}),
turf.point([36, 53], {hello: 'world'})
]);
turf.propEach(features, function (currentProperties, featureIndex) {
//=currentProperties
//=featureIndex
});propEachCallback
Callback for propEach
Type: Function
Parameters
currentPropertiesObject The current properties being processed.featureIndexnumber 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.
propReduceCallback
Callback for propReduce
The first time the callback function is called, the values provided as arguments depend on whether the reduce method has an initialValue argument.
If an initialValue is provided to the reduce method:
- The previousValue argument is initialValue.
- The currentValue argument is the value of the first element present in the array.
If an initialValue is not provided:
- The previousValue argument is the value of the first element present in the array.
- The currentValue argument is the value of the second element present in the array.
Type: Function
Parameters
previousValueany The accumulated value previously returned in the last invocation of the callback, or initialValue, if supplied.currentPropertiesany The current properties being processed.featureIndexnumber 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.
propReduce
Reduce properties in any GeoJSON object into a single value, similar to how Array.reduce works. However, in this case we lazily run the reduction, so an array of all properties is unnecessary.
Parameters
geojson(FeatureCollection | Feature) any GeoJSON objectcallbackFunction a method that takes (previousValue, currentProperties, featureIndex)initialValueany? Value to use as the first argument to the first call of the callback.
Examples
var features = turf.featureCollection([
turf.point([26, 37], {foo: 'bar'}),
turf.point([36, 53], {hello: 'world'})
]);
turf.propReduce(features, function (previousValue, currentProperties, featureIndex) {
//=previousValue
//=currentProperties
//=featureIndex
return currentProperties
});Returns any The value that results from the reduction.
featureEachCallback
Callback for featureEach
Type: Function
Parameters
currentFeatureFeature<any> The current feature being processed.featureIndexnumber 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.
featureEach
Iterate over features in any GeoJSON object, similar to Array.forEach.
Parameters
geojson(FeatureCollection | Feature | Geometry) any GeoJSON objectcallbackFunction a method that takes (currentFeature, featureIndex)
Examples
var features = turf.featureCollection([
turf.point([26, 37], {foo: 'bar'}),
turf.point([36, 53], {hello: 'world'})
]);
turf.featureEach(features, function (currentFeature, featureIndex) {
//=currentFeature
//=featureIndex
});featureReduceCallback
Callback for featureReduce
The first time the callback function is called, the values provided as arguments depend on whether the reduce method has an initialValue argument.
If an initialValue is provided to the reduce method:
- The previousValue argument is initialValue.
- The currentValue argument is the value of the first element present in the array.
If an initialValue is not provided:
- The previousValue argument is the value of the first element present in the array.
- The currentValue argument is the value of the second element present in the array.
Type: Function
Parameters
previousValueany The accumulated value previously returned in the last invocation of the callback, or initialValue, if supplied.currentFeatureFeature The current Feature being processed.featureIndexnumber 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.
featureReduce
Reduce features in any GeoJSON object, similar to Array.reduce().
Parameters
geojson(FeatureCollection | Feature | Geometry) any GeoJSON objectcallbackFunction a method that takes (previousValue, currentFeature, featureIndex)initialValueany? Value to use as the first argument to the first call of the callback.
Examples
var features = turf.featureCollection([
turf.point([26, 37], {"foo": "bar"}),
turf.point([36, 53], {"hello": "world"})
]);
turf.featureReduce(features, function (previousValue, currentFeature, featureIndex) {
//=previousValue
//=currentFeature
//=featureIndex
return currentFeature
});Returns any The value that results from the reduction.
coordAll
Get all coordinates from any GeoJSON object.
Parameters
geojson(FeatureCollection | Feature | Geometry) any GeoJSON object
Examples
var features = turf.featureCollection([
turf.point([26, 37], {foo: 'bar'}),
turf.point([36, 53], {hello: 'world'})
]);
var coords = turf.coordAll(features);
//= [[26, 37], [36, 53]]Returns Array<Array<number>> coordinate position array
geomEachCallback
Callback for geomEach
Type: Function
Parameters
currentGeometryGeometry The current geometry being processed.currentIndexnumber 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.currentPropertiesnumber The current feature properties being processed.
geomEach
Iterate over each geometry in any GeoJSON object, similar to Array.forEach()
Parameters
geojson(FeatureCollection | Feature | Geometry) any GeoJSON objectcallbackFunction a method that takes (currentGeometry, featureIndex, currentProperties)
Examples
var features = turf.featureCollection([
turf.point([26, 37], {foo: 'bar'}),
turf.point([36, 53], {hello: 'world'})
]);
turf.geomEach(features, function (currentGeometry, featureIndex, currentProperties) {
//=currentGeometry
//=featureIndex
//=currentProperties
});geomReduceCallback
Callback for geomReduce
The first time the callback function is called, the values provided as arguments depend on whether the reduce method has an initialValue argument.
If an initialValue is provided to the reduce method:
- The previousValue argument is initialValue.
- The currentValue argument is the value of the first element present in the array.
If an initialValue is not provided:
- The previousValue argument is the value of the first element present in the array.
- The currentValue argument is the value of the second element present in the array.
Type: Function
Parameters
previousValueany The accumulated value previously returned in the last invocation of the callback, or initialValue, if supplied.currentGeometryGeometry The current Feature being processed.currentIndexnumber 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.currentPropertiesObject The current feature properties being processed.
geomReduce
Reduce geometry in any GeoJSON object, similar to Array.reduce().
Parameters
geojson(FeatureCollection | Feature | Geometry) any GeoJSON objectcallbackFunction a method that takes (previousValue, currentGeometry, featureIndex, currentProperties)initialValueany? Value to use as the first argument to the first call of the callback.
Examples
var features = turf.featureCollection([
turf.point([26, 37], {foo: 'bar'}),
turf.point([36, 53], {hello: 'world'})
]);
turf.geomReduce(features, function (previousValue, currentGeometry, featureIndex, currentProperties) {
//=previousValue
//=currentGeometry
//=featureIndex
//=currentProperties
return currentGeometry
});Returns any The value that results from the reduction.
flattenEachCallback
Callback for flattenEach
Type: Function
Parameters
currentFeatureFeature The current flattened feature being processed.featureIndexnumber 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.featureSubIndexnumber 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.
flattenEach
Iterate over flattened features in any GeoJSON object, similar to Array.forEach.
Parameters
geojson(FeatureCollection | Feature | Geometry) any GeoJSON objectcallbackFunction a method that takes (currentFeature, featureIndex, featureSubIndex)
Examples
var features = turf.featureCollection([
turf.point([26, 37], {foo: 'bar'}),
turf.multiPoint([[40, 30], [36, 53]], {hello: 'world'})
]);
turf.flattenEach(features, function (currentFeature, featureIndex, featureSubIndex) {
//=currentFeature
//=featureIndex
//=featureSubIndex
});flattenReduceCallback
Callback for flattenReduce
The first time the callback function is called, the values provided as arguments depend on whether the reduce method has an initialValue argument.
If an initialValue is provided to the reduce method:
- The previousValue argument is initialValue.
- The currentValue argument is the value of the first element present in the array.
If an initialValue is not provided:
- The previousValue argument is the value of the first element present in the array.
- The currentValue argument is the value of the second element present in the array.
Type: Function
Parameters
previousValueany The accumulated value previously returned in the last invocation of the callback, or initialValue, if supplied.currentFeatureFeature The current Feature being processed.featureIndexnumber 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.featureSubIndexnumber 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.
flattenReduce
Reduce flattened features in any GeoJSON object, similar to Array.reduce().
Parameters
geojson(FeatureCollection | Feature | Geometry) any GeoJSON objectcallbackFunction a method that takes (previousValue, currentFeature, featureIndex, featureSubIndex)initialValueany? Value to use as the first argument to the first call of the callback.
Examples
var features = turf.featureCollection([
turf.point([26, 37], {foo: 'bar'}),
turf.multiPoint([[40, 30], [36, 53]], {hello: 'world'})
]);
turf.flattenReduce(features, function (previousValue, currentFeature, featureIndex, featureSubIndex) {
//=previousValue
//=currentFeature
//=featureIndex
//=featureSubIndex
return currentFeature
});Returns any The value that results from the reduction.
segmentEachCallback
Callback for segmentEach
Type: Function
Parameters
currentSegmentFeature<LineString> The current segment being processed.featureIndexnumber The featureIndex currently being processed, starts at index 0.featureSubIndexnumber The featureSubIndex currently being processed, starts at index 0.segmentIndexnumber The segmentIndex currently being processed, starts at index 0.
Returns void
segmentEach
Iterate over 2-vertex line segment in any GeoJSON object, similar to Array.forEach() (Multi)Point geometries do not contain segments therefore they are ignored during this operation.
Parameters
geojson(FeatureCollection | Feature | Geometry) any GeoJSONcallbackFunction a method that takes (currentSegment, featureIndex, featureSubIndex)
Examples
var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
// Iterate over GeoJSON by 2-vertex segments
turf.segmentEach(polygon, function (currentSegment, featureIndex, featureSubIndex, segmentIndex) {
//= currentSegment
//= featureIndex
//= featureSubIndex
//= segmentIndex
});
// Calculate the total number of segments
var total = 0;
turf.segmentEach(polygon, function () {
total++;
});Returns void
segmentReduceCallback
Callback for segmentReduce
The first time the callback function is called, the values provided as arguments depend on whether the reduce method has an initialValue argument.
If an initialValue is provided to the reduce method:
- The previousValue argument is initialValue.
- The currentValue argument is the value of the first element present in the array.
If an initialValue is not provided:
- The previousValue argument is the value of the first element present in the array.
- The currentValue argument is the value of the second element present in the array.
Type: Function
Parameters
previousValueany? The accumulated value previously returned in the last invocation of the callback, or initialValue, if supplied.currentSegmentFeature<LineString>? The current segment being processed.featureIndexnumber The featureIndex currently being processed, starts at index 0.featureSubIndexnumber The featureSubIndex currently being processed, starts at index 0.segmentIndexnumber The segmentIndex currently being processed, starts at index 0.
segmentReduce
Reduce 2-vertex line segment in any GeoJSON object, similar to Array.reduce() (Multi)Point geometries do not contain segments therefore they are ignored during this operation.
Parameters
geojson(FeatureCollection | Feature | Geometry) any GeoJSONcallbackFunction a method that takes (previousValue, currentSegment, currentIndex)initialValueany? Value to use as the first argument to the first call of the callback.
Examples
var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
// Iterate over GeoJSON by 2-vertex segments
turf.segmentReduce(polygon, function (previousSegment, currentSegment, featureIndex, featureSubIndex, segmentIndex) {
//= previousSegment
//= currentSegment
//= featureIndex
//= featureSubIndex
//= segmentInex
return currentSegment
});
// Calculate the total number of segments
var initialValue = 0
var total = turf.segmentReduce(polygon, function (previousValue) {
previousValue++;
return previousValue;
}, initialValue);Returns void
lineEachCallback
Callback for lineEach
Type: Function
Parameters
currentLineFeature<LineString> The current LineString|LinearRing being processed.lineIndexnumber The index of the current element being processed in the array, starts at index 0.lineSubIndexnumber The sub-index of the current line being processed at index 0
lineEach
Iterate over line or ring coordinates in LineString, Polygon, MultiLineString, MultiPolygon Features or Geometries, similar to Array.forEach.
Parameters
geojson(Geometry | Feature<(LineString | Polygon | MultiLineString | MultiPolygon)>) objectcallbackFunction a method that takes (currentLine, lineIndex, lineSubIndex)
Examples
var mtLn = turf.multiLineString([
turf.lineString([[26, 37], [35, 45]]),
turf.lineString([[36, 53], [38, 50], [41, 55]])
]);
turf.lineEach(mtLn, function (currentLine, lineIndex) {
//=currentLine
//=lineIndex
});lineReduceCallback
Callback for lineReduce
The first time the callback function is called, the values provided as arguments depend on whether the reduce method has an initialValue argument.
If an initialValue is provided to the reduce method:
- The previousValue argument is initialValue.
- The currentValue argument is the value of the first element present in the array.
If an initialValue is not provided:
- The previousValue argument is the value of the first element present in the array.
- The currentValue argument is the value of the second element present in the array.
Type: Function
Parameters
previousValueany The accumulated value previously returned in the last invocation of the callback, or initialValue, if supplied.currentLineFeature<LineString> The current LineString|LinearRing being processed.lineIndexnumber 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.lineSubIndexnumber The sub-index of the current line being processed at index 0
lineReduce
Reduce features in any GeoJSON object, similar to Array.reduce().
Parameters
geojson(Geometry | Feature<(LineString | Polygon | MultiLineString | MultiPolygon)>) objectcallbackFunction a method that takes (previousValue, currentFeature, featureIndex)initialValueany? Value to use as the first argument to the first call of the callback.
Examples
var mtp = turf.multiPolygon([
turf.polygon([[[12,48],[2,41],[24,38],[12,48]], [[9,44],[13,41],[13,45],[9,44]]]),
turf.polygon([[[5, 5], [0, 0], [2, 2], [4, 4], [5, 5]]])
]);
turf.lineReduce(mtp, function (previousValue, currentLine, lineIndex, lineSubIndex) {
//=previousValue
//=currentLine
//=lineIndex
//=lineSubIndex
return currentLine
}, 2);Returns any The value that results from the reduction.
This module is part of the Turfjs project, an open source module collection dedicated to geographic algorithms. It is maintained in the Turfjs/turf repository, where you can create PRs and issues.
Installation
Install this module individually:
$ npm install @turf/metaOr install the Turf module that includes it as a function:
$ npm install @turf/turf