geojson-rbush
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -12,6 +12,6 @@ import rbush from './rbush'; | ||
* @example | ||
* import geojsonRbush from 'geojson-rbush'; | ||
* var tree = geojsonRbush(); | ||
* import rbush from 'geojson-rbush'; | ||
* const tree = rbush(); | ||
*/ | ||
function geojsonRbush(maxEntries) { | ||
function geojsonRbush (maxEntries) { | ||
var tree = rbush(maxEntries); | ||
@@ -18,0 +18,0 @@ /** |
684
main.js
'use strict'; | ||
var meta = require('@turf/meta'); | ||
function quickselect(arr, k, left, right, compare) { | ||
@@ -8,3 +10,2 @@ quickselectStep(arr, k, left || 0, right || (arr.length - 1), compare || defaultCompare); | ||
function quickselectStep(arr, k, left, right, compare) { | ||
while (right > left) { | ||
@@ -615,672 +616,2 @@ if (right - left > 600) { | ||
/** | ||
* Callback for coordEach | ||
* | ||
* @callback coordEachCallback | ||
* @param {Array<number>} currentCoord The current coordinate being processed. | ||
* @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. | ||
*/ | ||
/** | ||
* Iterate over coordinates in any GeoJSON object, similar to Array.forEach() | ||
* | ||
* @name coordEach | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (currentCoord, coordIndex, featureIndex, featureSubIndex) | ||
* @param {boolean} [excludeWrapCoord=false] whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration. | ||
* @example | ||
* 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 | ||
* }); | ||
*/ | ||
function coordEach(geojson, callback, excludeWrapCoord) { | ||
// Handles null Geometry -- Skips this GeoJSON | ||
if (geojson === null) return; | ||
var featureIndex, geometryIndex, j, k, l, geometry, stopG, coords, | ||
geometryMaybeCollection, | ||
wrapShrink = 0, | ||
coordIndex = 0, | ||
isGeometryCollection, | ||
type = geojson.type, | ||
isFeatureCollection = type === 'FeatureCollection', | ||
isFeature = type === 'Feature', | ||
stop = isFeatureCollection ? geojson.features.length : 1; | ||
// This logic may look a little weird. The reason why it is that way | ||
// is because it's trying to be fast. GeoJSON supports multiple kinds | ||
// of objects at its root: FeatureCollection, Features, Geometries. | ||
// This function has the responsibility of handling all of them, and that | ||
// means that some of the `for` loops you see below actually just don't apply | ||
// to certain inputs. For instance, if you give this just a | ||
// Point geometry, then both loops are short-circuited and all we do | ||
// is gradually rename the input until it's called 'geometry'. | ||
// | ||
// This also aims to allocate as few resources as possible: just a | ||
// few numbers and booleans, rather than any temporary arrays as would | ||
// be required with the normalization approach. | ||
for (featureIndex = 0; featureIndex < stop; featureIndex++) { | ||
geometryMaybeCollection = (isFeatureCollection ? geojson.features[featureIndex].geometry : | ||
(isFeature ? geojson.geometry : geojson)); | ||
isGeometryCollection = (geometryMaybeCollection) ? geometryMaybeCollection.type === 'GeometryCollection' : false; | ||
stopG = isGeometryCollection ? geometryMaybeCollection.geometries.length : 1; | ||
for (geometryIndex = 0; geometryIndex < stopG; geometryIndex++) { | ||
var featureSubIndex = 0; | ||
geometry = isGeometryCollection ? | ||
geometryMaybeCollection.geometries[geometryIndex] : geometryMaybeCollection; | ||
// Handles null Geometry -- Skips this geometry | ||
if (geometry === null) continue; | ||
coords = geometry.coordinates; | ||
var geomType = geometry.type; | ||
wrapShrink = (excludeWrapCoord && (geomType === 'Polygon' || geomType === 'MultiPolygon')) ? 1 : 0; | ||
switch (geomType) { | ||
case null: | ||
break; | ||
case 'Point': | ||
callback(coords, coordIndex, featureIndex, featureSubIndex); | ||
coordIndex++; | ||
featureSubIndex++; | ||
break; | ||
case 'LineString': | ||
case 'MultiPoint': | ||
for (j = 0; j < coords.length; j++) { | ||
callback(coords[j], coordIndex, featureIndex, featureSubIndex); | ||
coordIndex++; | ||
if (geomType === 'MultiPoint') featureSubIndex++; | ||
} | ||
if (geomType === 'LineString') featureSubIndex++; | ||
break; | ||
case 'Polygon': | ||
case 'MultiLineString': | ||
for (j = 0; j < coords.length; j++) { | ||
for (k = 0; k < coords[j].length - wrapShrink; k++) { | ||
callback(coords[j][k], coordIndex, featureIndex, featureSubIndex); | ||
coordIndex++; | ||
} | ||
if (geomType === 'MultiLineString') featureSubIndex++; | ||
} | ||
if (geomType === 'Polygon') featureSubIndex++; | ||
break; | ||
case 'MultiPolygon': | ||
for (j = 0; j < coords.length; j++) { | ||
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); | ||
coordIndex++; | ||
} | ||
featureSubIndex++; | ||
} | ||
break; | ||
case 'GeometryCollection': | ||
for (j = 0; j < geometry.geometries.length; j++) | ||
coordEach(geometry.geometries[j], callback, excludeWrapCoord); | ||
break; | ||
default: | ||
throw new Error('Unknown Geometry Type'); | ||
} | ||
} | ||
} | ||
} | ||
/** | ||
* Callback for coordReduce | ||
* | ||
* The first time the callback function is called, the values provided as arguments depend | ||
* on whether the reduce method has an initialValue argument. | ||
* | ||
* If an initialValue is provided to the reduce method: | ||
* - The previousValue argument is initialValue. | ||
* - The currentValue argument is the value of the first element present in the array. | ||
* | ||
* If an initialValue is not provided: | ||
* - The previousValue argument is the value of the first element present in the array. | ||
* - The currentValue argument is the value of the second element present in the array. | ||
* | ||
* @callback coordReduceCallback | ||
* @param {*} previousValue The accumulated value previously returned in the last invocation | ||
* of the callback, or initialValue, if supplied. | ||
* @param {Array<number>} currentCoord The current coordinate being processed. | ||
* @param {number} coordIndex The current index of the coordinate being processed. | ||
* Starts at index 0, if an initialValue is provided, and at index 1 otherwise. | ||
* @param {number} featureIndex The current index of the feature being processed. | ||
* @param {number} featureSubIndex The current subIndex of the feature being processed. | ||
*/ | ||
/** | ||
* Reduce coordinates in any GeoJSON object, similar to Array.reduce() | ||
* | ||
* @name coordReduce | ||
* @param {FeatureCollection|Geometry|Feature} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (previousValue, currentCoord, coordIndex) | ||
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback. | ||
* @param {boolean} [excludeWrapCoord=false] whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration. | ||
* @returns {*} The value that results from the reduction. | ||
* @example | ||
* var features = turf.featureCollection([ | ||
* turf.point([26, 37], {"foo": "bar"}), | ||
* turf.point([36, 53], {"hello": "world"}) | ||
* ]); | ||
* | ||
* turf.coordReduce(features, function (previousValue, currentCoord, coordIndex, featureIndex, featureSubIndex) { | ||
* //=previousValue | ||
* //=currentCoord | ||
* //=coordIndex | ||
* //=featureIndex | ||
* //=featureSubIndex | ||
* return currentCoord; | ||
* }); | ||
*/ | ||
/** | ||
* Callback for propEach | ||
* | ||
* @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. | ||
*/ | ||
/** | ||
* Iterate over properties in any GeoJSON object, similar to Array.forEach() | ||
* | ||
* @name propEach | ||
* @param {(FeatureCollection|Feature)} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (currentProperties, featureIndex) | ||
* @example | ||
* var features = turf.featureCollection([ | ||
* turf.point([26, 37], {foo: 'bar'}), | ||
* turf.point([36, 53], {hello: 'world'}) | ||
* ]); | ||
* | ||
* turf.propEach(features, function (currentProperties, featureIndex) { | ||
* //=currentProperties | ||
* //=featureIndex | ||
* }); | ||
*/ | ||
/** | ||
* Callback for propReduce | ||
* | ||
* The first time the callback function is called, the values provided as arguments depend | ||
* on whether the reduce method has an initialValue argument. | ||
* | ||
* If an initialValue is provided to the reduce method: | ||
* - The previousValue argument is initialValue. | ||
* - The currentValue argument is the value of the first element present in the array. | ||
* | ||
* If an initialValue is not provided: | ||
* - The previousValue argument is the value of the first element present in the array. | ||
* - The currentValue argument is the value of the second element present in the array. | ||
* | ||
* @callback propReduceCallback | ||
* @param {*} previousValue The accumulated value previously returned in the last invocation | ||
* 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. | ||
*/ | ||
/** | ||
* 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. | ||
* | ||
* @name propReduce | ||
* @param {(FeatureCollection|Feature)} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (previousValue, currentProperties, featureIndex) | ||
* @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 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 | ||
* }); | ||
*/ | ||
/** | ||
* Callback for featureEach | ||
* | ||
* @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. | ||
*/ | ||
/** | ||
* Iterate over features in any GeoJSON object, similar to | ||
* Array.forEach. | ||
* | ||
* @name featureEach | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (currentFeature, featureIndex) | ||
* @example | ||
* var features = turf.featureCollection([ | ||
* turf.point([26, 37], {foo: 'bar'}), | ||
* turf.point([36, 53], {hello: 'world'}) | ||
* ]); | ||
* | ||
* turf.featureEach(features, function (currentFeature, featureIndex) { | ||
* //=currentFeature | ||
* //=featureIndex | ||
* }); | ||
*/ | ||
function featureEach(geojson, callback) { | ||
if (geojson.type === 'Feature') { | ||
callback(geojson, 0); | ||
} else if (geojson.type === 'FeatureCollection') { | ||
for (var i = 0; i < geojson.features.length; i++) { | ||
callback(geojson.features[i], i); | ||
} | ||
} | ||
} | ||
/** | ||
* Callback for featureReduce | ||
* | ||
* The first time the callback function is called, the values provided as arguments depend | ||
* on whether the reduce method has an initialValue argument. | ||
* | ||
* If an initialValue is provided to the reduce method: | ||
* - The previousValue argument is initialValue. | ||
* - The currentValue argument is the value of the first element present in the array. | ||
* | ||
* If an initialValue is not provided: | ||
* - The previousValue argument is the value of the first element present in the array. | ||
* - The currentValue argument is the value of the second element present in the array. | ||
* | ||
* @callback featureReduceCallback | ||
* @param {*} previousValue The accumulated value previously returned in the last invocation | ||
* of the callback, or initialValue, if supplied. | ||
* @param {Feature} currentFeature The current Feature being processed. | ||
* @param {number} featureIndex The index of the current element being processed in the | ||
* array.Starts at index 0, if an initialValue is provided, and at index 1 otherwise. | ||
*/ | ||
/** | ||
* Reduce features in any GeoJSON object, similar to Array.reduce(). | ||
* | ||
* @name featureReduce | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (previousValue, currentFeature, featureIndex) | ||
* @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 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 | ||
* }); | ||
*/ | ||
/** | ||
* Get all coordinates from any GeoJSON object. | ||
* | ||
* @name coordAll | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON object | ||
* @returns {Array<Array<number>>} coordinate position array | ||
* @example | ||
* var features = turf.featureCollection([ | ||
* turf.point([26, 37], {foo: 'bar'}), | ||
* turf.point([36, 53], {hello: 'world'}) | ||
* ]); | ||
* | ||
* var coords = turf.coordAll(features); | ||
* //= [[26, 37], [36, 53]] | ||
*/ | ||
/** | ||
* Callback for geomEach | ||
* | ||
* @callback geomEachCallback | ||
* @param {Geometry} currentGeometry The current geometry 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 {number} currentProperties The current feature properties being processed. | ||
*/ | ||
/** | ||
* Iterate over each geometry in any GeoJSON object, similar to Array.forEach() | ||
* | ||
* @name geomEach | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (currentGeometry, featureIndex, currentProperties) | ||
* @example | ||
* 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 | ||
* }); | ||
*/ | ||
/** | ||
* Callback for geomReduce | ||
* | ||
* The first time the callback function is called, the values provided as arguments depend | ||
* on whether the reduce method has an initialValue argument. | ||
* | ||
* If an initialValue is provided to the reduce method: | ||
* - The previousValue argument is initialValue. | ||
* - The currentValue argument is the value of the first element present in the array. | ||
* | ||
* If an initialValue is not provided: | ||
* - The previousValue argument is the value of the first element present in the array. | ||
* - The currentValue argument is the value of the second element present in the array. | ||
* | ||
* @callback geomReduceCallback | ||
* @param {*} previousValue The accumulated value previously returned in the last invocation | ||
* 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. | ||
*/ | ||
/** | ||
* Reduce geometry in any GeoJSON object, similar to Array.reduce(). | ||
* | ||
* @name geomReduce | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (previousValue, currentGeometry, featureIndex, currentProperties) | ||
* @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 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 | ||
* }); | ||
*/ | ||
/** | ||
* Callback for flattenEach | ||
* | ||
* @callback flattenEachCallback | ||
* @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. | ||
*/ | ||
/** | ||
* Iterate over flattened features in any GeoJSON object, similar to | ||
* Array.forEach. | ||
* | ||
* @name flattenEach | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (currentFeature, featureIndex, featureSubIndex) | ||
* @example | ||
* var features = turf.featureCollection([ | ||
* turf.point([26, 37], {foo: 'bar'}), | ||
* turf.multiPoint([[40, 30], [36, 53]], {hello: 'world'}) | ||
* ]); | ||
* | ||
* turf.flattenEach(features, function (currentFeature, featureIndex, featureSubIndex) { | ||
* //=currentFeature | ||
* //=featureIndex | ||
* //=featureSubIndex | ||
* }); | ||
*/ | ||
/** | ||
* Callback for flattenReduce | ||
* | ||
* The first time the callback function is called, the values provided as arguments depend | ||
* on whether the reduce method has an initialValue argument. | ||
* | ||
* If an initialValue is provided to the reduce method: | ||
* - The previousValue argument is initialValue. | ||
* - The currentValue argument is the value of the first element present in the array. | ||
* | ||
* If an initialValue is not provided: | ||
* - The previousValue argument is the value of the first element present in the array. | ||
* - The currentValue argument is the value of the second element present in the array. | ||
* | ||
* @callback flattenReduceCallback | ||
* @param {*} previousValue The accumulated value previously returned in the last invocation | ||
* of the callback, or initialValue, if supplied. | ||
* @param {Feature} currentFeature The current Feature being processed. | ||
* @param {number} featureIndex The 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. | ||
*/ | ||
/** | ||
* Reduce flattened features in any GeoJSON object, similar to Array.reduce(). | ||
* | ||
* @name flattenReduce | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON object | ||
* @param {Function} callback a method that takes (previousValue, currentFeature, featureIndex, featureSubIndex) | ||
* @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 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 | ||
* }); | ||
*/ | ||
/** | ||
* Callback for segmentEach | ||
* | ||
* @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. | ||
* @returns {void} | ||
*/ | ||
/** | ||
* Iterate over 2-vertex line segment in any GeoJSON object, similar to Array.forEach() | ||
* (Multi)Point geometries do not contain segments therefore they are ignored during this operation. | ||
* | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON | ||
* @param {Function} callback a method that takes (currentSegment, featureIndex, featureSubIndex) | ||
* @returns {void} | ||
* @example | ||
* var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]); | ||
* | ||
* // Iterate over GeoJSON by 2-vertex segments | ||
* turf.segmentEach(polygon, function (currentSegment, featureIndex, featureSubIndex, segmentIndex) { | ||
* //= currentSegment | ||
* //= featureIndex | ||
* //= featureSubIndex | ||
* //= segmentIndex | ||
* }); | ||
* | ||
* // Calculate the total number of segments | ||
* var total = 0; | ||
* turf.segmentEach(polygon, function () { | ||
* total++; | ||
* }); | ||
*/ | ||
/** | ||
* Callback for segmentReduce | ||
* | ||
* The first time the callback function is called, the values provided as arguments depend | ||
* on whether the reduce method has an initialValue argument. | ||
* | ||
* If an initialValue is provided to the reduce method: | ||
* - The previousValue argument is initialValue. | ||
* - The currentValue argument is the value of the first element present in the array. | ||
* | ||
* If an initialValue is not provided: | ||
* - The previousValue argument is the value of the first element present in the array. | ||
* - The currentValue argument is the value of the second element present in the array. | ||
* | ||
* @callback segmentReduceCallback | ||
* @param {*} [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. | ||
*/ | ||
/** | ||
* Reduce 2-vertex line segment in any GeoJSON object, similar to Array.reduce() | ||
* (Multi)Point geometries do not contain segments therefore they are ignored during this operation. | ||
* | ||
* @param {(FeatureCollection|Feature|Geometry)} geojson any GeoJSON | ||
* @param {Function} callback a method that takes (previousValue, currentSegment, currentIndex) | ||
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback. | ||
* @returns {void} | ||
* @example | ||
* var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]); | ||
* | ||
* // Iterate over GeoJSON by 2-vertex segments | ||
* turf.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); | ||
*/ | ||
/** | ||
* Callback for lineEach | ||
* | ||
* @callback lineEachCallback | ||
* @param {Feature<LineString>} currentLine The current LineString|LinearRing being processed. | ||
* @param {number} lineIndex The index of the current element being processed in the array, starts at index 0. | ||
* @param {number} lineSubIndex The sub-index of the current line being processed at index 0 | ||
*/ | ||
/** | ||
* Iterate over line or ring coordinates in LineString, Polygon, MultiLineString, MultiPolygon Features or Geometries, | ||
* similar to Array.forEach. | ||
* | ||
* @name lineEach | ||
* @param {Geometry|Feature<LineString|Polygon|MultiLineString|MultiPolygon>} geojson object | ||
* @param {Function} callback a method that takes (currentLine, lineIndex, lineSubIndex) | ||
* @example | ||
* 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 | ||
* }); | ||
*/ | ||
/** | ||
* Callback for lineReduce | ||
* | ||
* The first time the callback function is called, the values provided as arguments depend | ||
* on whether the reduce method has an initialValue argument. | ||
* | ||
* If an initialValue is provided to the reduce method: | ||
* - The previousValue argument is initialValue. | ||
* - The currentValue argument is the value of the first element present in the array. | ||
* | ||
* If an initialValue is not provided: | ||
* - The previousValue argument is the value of the first element present in the array. | ||
* - The currentValue argument is the value of the second element present in the array. | ||
* | ||
* @callback lineReduceCallback | ||
* @param {*} previousValue The accumulated value previously returned in the last invocation | ||
* of the callback, or initialValue, if supplied. | ||
* @param {Feature<LineString>} currentLine The current LineString|LinearRing being processed. | ||
* @param {number} lineIndex 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} lineSubIndex The sub-index of the current line being processed at index 0 | ||
*/ | ||
/** | ||
* Reduce features in any GeoJSON object, similar to Array.reduce(). | ||
* | ||
* @name lineReduce | ||
* @param {Geometry|Feature<LineString|Polygon|MultiLineString|MultiPolygon>} geojson object | ||
* @param {Function} callback a method that takes (previousValue, currentFeature, featureIndex) | ||
* @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([ | ||
* 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); | ||
*/ | ||
/** | ||
* GeoJSON implementation of [RBush](https://github.com/mourner/rbush#rbush) spatial index. | ||
@@ -1293,6 +624,6 @@ * | ||
* @example | ||
* import geojsonRbush from 'geojson-rbush'; | ||
* var tree = geojsonRbush(); | ||
* import rbush from 'geojson-rbush'; | ||
* const tree = rbush(); | ||
*/ | ||
function geojsonRbush(maxEntries) { | ||
function geojsonRbush (maxEntries) { | ||
var tree = rbush(maxEntries); | ||
@@ -1366,3 +697,3 @@ /** | ||
// Load FeatureCollection | ||
featureEach(features, function (feature) { | ||
meta.featureEach(features, function (feature) { | ||
feature.bbox = feature.bbox ? feature.bbox : turfBBox(feature); | ||
@@ -1587,3 +918,3 @@ load.push(feature); | ||
var bbox = [Infinity, Infinity, -Infinity, -Infinity]; | ||
coordEach(geojson, function (coord) { | ||
meta.coordEach(geojson, function (coord) { | ||
if (bbox[0] > coord[0]) bbox[0] = coord[0]; | ||
@@ -1598,2 +929,1 @@ if (bbox[1] > coord[1]) bbox[1] = coord[1]; | ||
module.exports = geojsonRbush; | ||
module.exports.default = geojsonRbush; |
{ | ||
"name": "geojson-rbush", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "GeoJSON implementation of RBush", | ||
@@ -10,4 +10,4 @@ "main": "main", | ||
"files": [ | ||
"index.d.ts", | ||
"index.js", | ||
"index.d.ts", | ||
"main.js", | ||
@@ -18,7 +18,5 @@ "rbush.js", | ||
"scripts": { | ||
"pretest": "rollup -c rollup.config.js", | ||
"test": "tap test.js", | ||
"posttest": "eslint index.js", | ||
"bench": "node bench.js", | ||
"docs": "documentation readme index.js --shallow --section=API --markdown-toc" | ||
"pretest": "rollup -f cjs -o main.js index.js", | ||
"test": "node test.js", | ||
"bench": "node bench.js" | ||
}, | ||
@@ -40,19 +38,12 @@ "keywords": [ | ||
"devDependencies": { | ||
"@types/geojson": "*", | ||
"@types/rbush": "*", | ||
"@turf/random": "*", | ||
"benchmark": "*", | ||
"documentation": "*", | ||
"eslint": "*", | ||
"eslint-config-mourner": "*", | ||
"load-json-file": "*", | ||
"rollup": "^0.50.0", | ||
"rollup-plugin-node-resolve": "^3.0.0", | ||
"tap": "*", | ||
"rollup": "*", | ||
"tape": "*", | ||
"write-json-file": "*" | ||
}, | ||
"dependencies": { | ||
"@turf/helpers": "*", | ||
"@turf/meta": "*", | ||
"rbush": "*" | ||
"@turf/meta": "*" | ||
} | ||
} |
@@ -6,3 +6,2 @@ function quickselect(arr, k, left, right, compare) { | ||
function quickselectStep(arr, k, left, right, compare) { | ||
while (right > left) { | ||
@@ -9,0 +8,0 @@ if (right - left > 600) { |
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
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 2 instances in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1
6
1
62841
1541
6
- Removed@turf/helpers@*
- Removedrbush@*
- Removedquickselect@3.0.0(transitive)
- Removedrbush@4.0.1(transitive)