npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@spatial/meta

v2.0.0

Published

turf meta module

Downloads

2,307

Readme

@spatial/meta

coordEachCallback

Callback for coordEach

Type: Function

Parameters

  • currentCoord Array<number> The current coordinate being processed.
  • coordIndex number The current index of the coordinate being processed.
  • featureIndex number The current index of the Feature being processed.
  • multiFeatureIndex number The current index of the Multi-Feature being processed.
  • geometryIndex number The current index of the Geometry being processed.

coordEach

Iterate over coordinates in any GeoJSON object, similar to Array.forEach()

Parameters

  • geojson (FeatureCollection | Feature | Geometry) any GeoJSON object
  • callback Function a method that takes (currentCoord, coordIndex, featureIndex, multiFeatureIndex)
  • excludeWrapCoord boolean whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration. (optional, default false)

Examples

var features = turf.featureCollection([
  turf.point([26, 37], {"foo": "bar"}),
  turf.point([36, 53], {"hello": "world"})
]);

turf.coordEach(features, function (currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) {
  //=currentCoord
  //=coordIndex
  //=featureIndex
  //=multiFeatureIndex
  //=geometryIndex
});

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

  • previousValue any The accumulated value previously returned in the last invocation of the callback, or initialValue, if supplied.
  • currentCoord Array<number> The current coordinate being processed.
  • coordIndex number The current index of the coordinate being processed. Starts at index 0, if an initialValue is provided, and at index 1 otherwise.
  • featureIndex number The current index of the Feature being processed.
  • multiFeatureIndex number The current index of the Multi-Feature being processed.
  • geometryIndex number The current index of the Geometry being processed.

coordReduce

Reduce coordinates in any GeoJSON object, similar to Array.reduce()

Parameters

  • geojson (FeatureCollection | Geometry | Feature) any GeoJSON object
  • callback Function a method that takes (previousValue, currentCoord, coordIndex)
  • initialValue any? Value to use as the first argument to the first call of the callback.
  • excludeWrapCoord boolean whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration. (optional, default false)

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, multiFeatureIndex, geometryIndex) {
  //=previousValue
  //=currentCoord
  //=coordIndex
  //=featureIndex
  //=multiFeatureIndex
  //=geometryIndex
  return currentCoord;
});

Returns any The value that results from the reduction.

propEachCallback

Callback for propEach

Type: Function

Parameters

  • currentProperties Object The current Properties being processed.
  • featureIndex number The current index of the Feature being processed.

propEach

Iterate over properties in any GeoJSON object, similar to Array.forEach()

Parameters

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
});

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

  • previousValue any The accumulated value previously returned in the last invocation of the callback, or initialValue, if supplied.
  • currentProperties any The current Properties being processed.
  • featureIndex number The current index of the Feature being processed.

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 object
  • callback Function a method that takes (previousValue, currentProperties, featureIndex)
  • initialValue any? 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

  • currentFeature Feature<any> The current Feature being processed.
  • featureIndex number The current index of the Feature being processed.

featureEach

Iterate over features in any GeoJSON object, similar to Array.forEach.

Parameters

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

  • previousValue any The accumulated value previously returned in the last invocation of the callback, or initialValue, if supplied.
  • currentFeature Feature The current Feature being processed.
  • featureIndex number The current index of the Feature being processed.

featureReduce

Reduce features in any GeoJSON object, similar to Array.reduce().

Parameters

  • geojson (FeatureCollection | Feature | Geometry) any GeoJSON object
  • callback Function a method that takes (previousValue, currentFeature, featureIndex)
  • initialValue any? 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

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

  • currentGeometry Geometry The current Geometry being processed.
  • featureIndex number The current index of the Feature being processed.
  • featureProperties Object The current Feature Properties being processed.
  • featureBBox Array<number> The current Feature BBox being processed.
  • featureId (number | string) The current Feature Id being processed.

geomEach

Iterate over each geometry in any GeoJSON object, similar to Array.forEach()

Parameters

Examples

var features = turf.featureCollection([
    turf.point([26, 37], {foo: 'bar'}),
    turf.point([36, 53], {hello: 'world'})
]);

turf.geomEach(features, function (currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {
  //=currentGeometry
  //=featureIndex
  //=featureProperties
  //=featureBBox
  //=featureId
});

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

  • previousValue any The accumulated value previously returned in the last invocation of the callback, or initialValue, if supplied.
  • currentGeometry Geometry The current Geometry being processed.
  • featureIndex number The current index of the Feature being processed.
  • featureProperties Object The current Feature Properties being processed.
  • featureBBox Array<number> The current Feature BBox being processed.
  • featureId (number | string) The current Feature Id being processed.

geomReduce

Reduce geometry in any GeoJSON object, similar to Array.reduce().

Parameters

  • geojson (FeatureCollection | Feature | Geometry) any GeoJSON object
  • callback 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.

Examples

var features = turf.featureCollection([
    turf.point([26, 37], {foo: 'bar'}),
    turf.point([36, 53], {hello: 'world'})
]);

turf.geomReduce(features, function (previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {
  //=previousValue
  //=currentGeometry
  //=featureIndex
  //=featureProperties
  //=featureBBox
  //=featureId
  return currentGeometry
});

Returns any The value that results from the reduction.

flattenEachCallback

Callback for flattenEach

Type: Function

Parameters

  • currentFeature Feature The current flattened feature being processed.
  • featureIndex number The current index of the Feature being processed.
  • multiFeatureIndex number The current index of the Multi-Feature being processed.

flattenEach

Iterate over flattened features in any GeoJSON object, similar to Array.forEach.

Parameters

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, multiFeatureIndex) {
  //=currentFeature
  //=featureIndex
  //=multiFeatureIndex
});

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

  • previousValue any The accumulated value previously returned in the last invocation of the callback, or initialValue, if supplied.
  • currentFeature Feature The current Feature being processed.
  • featureIndex number The current index of the Feature being processed.
  • multiFeatureIndex number The current index of the Multi-Feature being processed.

flattenReduce

Reduce flattened features in any GeoJSON object, similar to Array.reduce().

Parameters

  • geojson (FeatureCollection | Feature | Geometry) any GeoJSON object
  • callback 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.

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, multiFeatureIndex) {
  //=previousValue
  //=currentFeature
  //=featureIndex
  //=multiFeatureIndex
  return currentFeature
});

Returns any The value that results from the reduction.

segmentEachCallback

Callback for segmentEach

Type: Function

Parameters

  • currentSegment Feature<LineString> The current Segment being processed.
  • featureIndex number The current index of the Feature being processed.
  • multiFeatureIndex number The current index of the Multi-Feature being processed.
  • geometryIndex number The current index of the Geometry being processed.
  • segmentIndex number The current index of the Segment being processed.

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

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, multiFeatureIndex, geometryIndex, segmentIndex) {
  //=currentSegment
  //=featureIndex
  //=multiFeatureIndex
  //=geometryIndex
  //=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

  • previousValue any The accumulated value previously returned in the last invocation of the callback, or initialValue, if supplied.
  • currentSegment Feature<LineString> The current Segment being processed.
  • featureIndex number The current index of the Feature being processed.
  • multiFeatureIndex number The current index of the Multi-Feature being processed.
  • geometryIndex number The current index of the Geometry being processed.
  • segmentIndex number The current index of the Segment being processed.

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 GeoJSON
  • callback Function a method that takes (previousValue, currentSegment, currentIndex)
  • initialValue any? 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, multiFeatureIndex, geometryIndex, segmentIndex) {
  //= previousSegment
  //= currentSegment
  //= featureIndex
  //= multiFeatureIndex
  //= geometryIndex
  //= 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

  • currentLine Feature<LineString> The current LineString|LinearRing being processed
  • featureIndex number The current index of the Feature being processed
  • multiFeatureIndex number The current index of the Multi-Feature being processed
  • geometryIndex number The current index of the Geometry being processed

lineEach

Iterate over line or ring coordinates in LineString, Polygon, MultiLineString, MultiPolygon Features or Geometries, similar to Array.forEach.

Parameters

Examples

var multiLine = turf.multiLineString([
  [[26, 37], [35, 45]],
  [[36, 53], [38, 50], [41, 55]]
]);

turf.lineEach(multiLine, function (currentLine, featureIndex, multiFeatureIndex, geometryIndex) {
  //=currentLine
  //=featureIndex
  //=multiFeatureIndex
  //=geometryIndex
});

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

  • previousValue any The accumulated value previously returned in the last invocation of the callback, or initialValue, if supplied.
  • currentLine Feature<LineString> The current LineString|LinearRing being processed.
  • featureIndex number The current index of the Feature being processed
  • multiFeatureIndex number The current index of the Multi-Feature being processed
  • geometryIndex number The current index of the Geometry being processed

lineReduce

Reduce features in any GeoJSON object, similar to Array.reduce().

Parameters

Examples

var multiPoly = turf.multiPolygon([
  turf.polygon([[[12,48],[2,41],[24,38],[12,48]], [[9,44],[13,41],[13,45],[9,44]]]),
  turf.polygon([[[5, 5], [0, 0], [2, 2], [4, 4], [5, 5]]])
]);

turf.lineReduce(multiPoly, function (previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex) {
  //=previousValue
  //=currentLine
  //=featureIndex
  //=multiFeatureIndex
  //=geometryIndex
  return currentLine
});

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 @spatial/meta

Or install the Turf module that includes it as a function:

$ npm install @turf/turf