JSPM

  • Created
  • Published
  • Downloads 4366683
  • Score
    100M100P100Q281125F
  • License MIT

turf meta module

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

coordEach

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

Parameters

  • layer Object any GeoJSON object
  • callback Function a method that takes (currentCoords, currentIndex)
  • 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 = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [26, 37]
      }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [36, 53]
      }
    }
  ]
};
turf.coordEach(features, function (currentCoords, currentIndex) {
  //=currentCoords
  //=currentIndex
});

coordReduce

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

Parameters

  • layer Object any GeoJSON object
  • callback Function a method that takes (previousValue, currentCoords, currentIndex)
  • 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 = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [26, 37]
      }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [36, 53]
      }
    }
  ]
};
turf.coordReduce(features, function (previousValue, currentCoords, currentIndex) {
  //=previousValue
  //=currentCoords
  //=currentIndex
  return currentCoords;
});

Returns Any The value that results from the reduction.

propEach

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

Parameters

  • layer Object any GeoJSON object
  • callback Function a method that takes (currentProperties, currentIndex)

Examples

var features = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {"foo": "bar"},
      "geometry": {
        "type": "Point",
        "coordinates": [26, 37]
      }
    },
    {
      "type": "Feature",
      "properties": {"hello": "world"},
      "geometry": {
        "type": "Point",
        "coordinates": [36, 53]
      }
    }
  ]
};
turf.propEach(features, function (currentProperties, currentIndex) {
  //=currentProperties
  //=currentIndex
});

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

  • layer Object any GeoJSON object
  • callback Function a method that takes (previousValue, currentProperties, currentIndex)
  • initialValue [Any] Value to use as the first argument to the first call of the callback.

Examples

var features = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {"foo": "bar"},
      "geometry": {
        "type": "Point",
        "coordinates": [26, 37]
      }
    },
    {
      "type": "Feature",
      "properties": {"hello": "world"},
      "geometry": {
        "type": "Point",
        "coordinates": [36, 53]
      }
    }
  ]
};
turf.propReduce(features, function (previousValue, currentProperties, currentIndex) {
  //=previousValue
  //=currentProperties
  //=currentIndex
  return currentProperties
});

Returns Any The value that results from the reduction.

featureEach

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

Parameters

  • layer Object any GeoJSON object
  • callback Function a method that takes (currentFeature, currentIndex)

Examples

var features = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [26, 37]
      }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [36, 53]
      }
    }
  ]
};
turf.featureEach(features, function (currentFeature, currentIndex) {
  //=currentFeature
  //=currentIndex
});

featureReduce

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

Parameters

  • layer Object any GeoJSON object
  • callback Function a method that takes (previousValue, currentFeature, currentIndex)
  • initialValue [Any] Value to use as the first argument to the first call of the callback.

Examples

var features = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {"foo": "bar"},
      "geometry": {
        "type": "Point",
        "coordinates": [26, 37]
      }
    },
    {
      "type": "Feature",
      "properties": {"hello": "world"},
      "geometry": {
        "type": "Point",
        "coordinates": [36, 53]
      }
    }
  ]
};
turf.featureReduce(features, function (previousValue, currentFeature, currentIndex) {
  //=previousValue
  //=currentFeature
  //=currentIndex
  return currentFeature
});

Returns Any The value that results from the reduction.

coordAll

Get all coordinates from any GeoJSON object.

Parameters

  • layer Object any GeoJSON object

Examples

var features = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [26, 37]
      }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [36, 53]
      }
    }
  ]
};
var coords = turf.coordAll(features);
//=coords

Returns Array<Array<number>> coordinate position array

geomEach

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

Parameters

  • layer Object any GeoJSON object
  • callback Function a method that takes (currentGeometry, currentIndex)

Examples

var features = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [26, 37]
      }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [36, 53]
      }
    }
  ]
};
turf.geomEach(features, function (currentGeometry, currentIndex) {
  //=currentGeometry
  //=currentIndex
});

geomReduce

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

Parameters

  • layer Object any GeoJSON object
  • callback Function a method that takes (previousValue, currentGeometry, currentIndex)
  • initialValue [Any] Value to use as the first argument to the first call of the callback.

Examples

var features = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {"foo": "bar"},
      "geometry": {
        "type": "Point",
        "coordinates": [26, 37]
      }
    },
    {
      "type": "Feature",
      "properties": {"hello": "world"},
      "geometry": {
        "type": "Point",
        "coordinates": [36, 53]
      }
    }
  ]
};
turf.geomReduce(features, function (previousValue, currentGeometry, currentIndex) {
  //=previousValue
  //=currentGeometry
  //=currentIndex
  return currentGeometry
});

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

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

$ npm install @turf/turf