Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
@turf/meta
Advanced tools
@turf/meta is a module of the Turf.js library that provides utility functions for working with GeoJSON data. It allows you to iterate over various GeoJSON objects, extract specific properties, and manipulate geometries.
coordEach
The `coordEach` function iterates over each coordinate in any GeoJSON object, allowing you to perform operations on each coordinate.
const turf = require('@turf/meta');
const point = { "type": "Feature", "geometry": { "type": "Point", "coordinates": [110, 50] } };
turf.coordEach(point, function (coord) {
console.log(coord);
});
propEach
The `propEach` function iterates over properties in any GeoJSON Feature or FeatureCollection, allowing you to access and manipulate properties.
const turf = require('@turf/meta');
const featureCollection = { "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": { "name": "A" }, "geometry": { "type": "Point", "coordinates": [110, 50] } } ] };
turf.propEach(featureCollection, function (properties, featureIndex) {
console.log(properties);
});
geomEach
The `geomEach` function iterates over each geometry in any GeoJSON object, allowing you to perform operations on each geometry.
const turf = require('@turf/meta');
const featureCollection = { "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": { "type": "Point", "coordinates": [110, 50] } } ] };
turf.geomEach(featureCollection, function (geometry, featureIndex) {
console.log(geometry);
});
The `geojson-utils` package provides utility functions for manipulating and analyzing GeoJSON data. It offers similar functionalities to @turf/meta, such as iterating over coordinates and geometries, but it also includes additional features like distance calculations and point-in-polygon tests.
The `geolib` package is a library for geospatial calculations. While it does not focus specifically on GeoJSON, it provides a wide range of geospatial utilities, including distance calculations, bounding box operations, and coordinate transformations. It can be used in conjunction with GeoJSON data for various geospatial tasks.
The `geojson-extent` package is designed to calculate the bounding box of GeoJSON objects. While it does not offer the same breadth of functionality as @turf/meta, it is useful for specific tasks related to determining the spatial extent of GeoJSON data.
Callback for coordEach
Type: Function
Parameters
currentCoord
Array<number> The current coordinate being processed.coordIndex
number The current index of the coordinate being processed.
Starts at index 0.featureIndex
number The current index of the feature being processed.featureSubIndex
number The current subIndex of the feature being processed.Iterate over coordinates in any GeoJSON object, similar to Array.forEach()
Parameters
geojson
(FeatureCollection | Feature | Geometry) any GeoJSON objectcallback
Function a method that takes (currentCoord, coordIndex, featureIndex, featureSubIndex)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, featureSubIndex) {
//=currentCoord
//=coordIndex
//=featureIndex
//=featureSubIndex
});
Reduce coordinates in any GeoJSON object, similar to Array.reduce()
Parameters
geojson
(FeatureCollection | Geometry | Feature) any GeoJSON objectcallback
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, featureSubIndex) {
//=previousValue
//=currentCoord
//=coordIndex
//=featureIndex
//=featureSubIndex
return currentCoord;
});
Returns any The value that results from the reduction.
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:
If an initialValue is not provided:
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.featureSubIndex
number The current subIndex of the feature being processed.Iterate over properties in any GeoJSON object, similar to Array.forEach()
Parameters
geojson
(FeatureCollection | Feature) any GeoJSON objectcallback
Function 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
});
Callback for propEach
Type: Function
Parameters
currentProperties
Object The current properties being processed.featureIndex
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.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:
If an initialValue is not provided:
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 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.
Parameters
geojson
(FeatureCollection | Feature) any GeoJSON objectcallback
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.
Callback for featureEach
Type: Function
Parameters
currentFeature
Feature<any> The current feature being processed.featureIndex
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.Iterate over features in any GeoJSON object, similar to Array.forEach.
Parameters
geojson
(FeatureCollection | Feature | Geometry) any GeoJSON objectcallback
Function 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
});
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:
If an initialValue is not provided:
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 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().
Parameters
geojson
(FeatureCollection | Feature | Geometry) any GeoJSON objectcallback
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.
Get all coordinates from any GeoJSON object.
Parameters
geojson
(FeatureCollection | Feature | Geometry) any GeoJSON objectExamples
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
Callback for geomEach
Type: Function
Parameters
currentGeometry
Geometry The current geometry being processed.currentIndex
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
number The current feature properties being processed.Iterate over each geometry in any GeoJSON object, similar to Array.forEach()
Parameters
geojson
(FeatureCollection | Feature | Geometry) any GeoJSON objectcallback
Function 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
});
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:
If an initialValue is not provided:
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 Feature being processed.currentIndex
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 The current feature properties being processed.Reduce geometry in any GeoJSON object, similar to Array.reduce().
Parameters
geojson
(FeatureCollection | Feature | Geometry) any GeoJSON objectcallback
Function a method that takes (previousValue, currentGeometry, featureIndex, currentProperties)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, currentProperties) {
//=previousValue
//=currentGeometry
//=featureIndex
//=currentProperties
return currentGeometry
});
Returns any The value that results from the reduction.
Callback for flattenEach
Type: Function
Parameters
currentFeature
Feature The current flattened feature being processed.featureIndex
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 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.
Parameters
geojson
(FeatureCollection | Feature | Geometry) any GeoJSON objectcallback
Function 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
});
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:
If an initialValue is not provided:
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 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 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().
Parameters
geojson
(FeatureCollection | Feature | Geometry) any GeoJSON objectcallback
Function a method that takes (previousValue, currentFeature, featureIndex, featureSubIndex)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, featureSubIndex) {
//=previousValue
//=currentFeature
//=featureIndex
//=featureSubIndex
return currentFeature
});
Returns any The value that results from the reduction.
Callback for segmentEach
Type: Function
Parameters
currentSegment
Feature<LineString> The current segment being processed.featureIndex
number The featureIndex currently being processed, starts at index 0.featureSubIndex
number The featureSubIndex currently being processed, starts at index 0.segmentIndex
number 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.
Parameters
geojson
(FeatureCollection | Feature | Geometry) any GeoJSONcallback
Function 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
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:
If an initialValue is not provided:
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 featureIndex currently being processed, starts at index 0.featureSubIndex
number The featureSubIndex currently being processed, starts at index 0.segmentIndex
number 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.
Parameters
geojson
(FeatureCollection | Feature | Geometry) any GeoJSONcallback
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, 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
Callback for lineEach
Type: Function
Parameters
currentLine
Feature<LineString> The current LineString|LinearRing being processed.lineIndex
number The index of the current element being processed in the array, starts at index 0.lineSubIndex
number The sub-index of the current line being processed at index 0Iterate 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)>) objectcallback
Function 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
});
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:
If an initialValue is not provided:
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.lineIndex
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.lineSubIndex
number The sub-index of the current line being processed at index 0Reduce features in any GeoJSON object, similar to Array.reduce().
Parameters
geojson
(Geometry | Feature<(LineString | Polygon | MultiLineString | MultiPolygon)>) objectcallback
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 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.
Install this module individually:
$ npm install @turf/meta
Or install the Turf module that includes it as a function:
$ npm install @turf/turf
5.0.0 🎉
Object
.@turf/voronoi
][voronoi]Takes a FeatureCollection of points, and a bounding box, and returns a FeatureCollection of Voronoi polygons. (PR https://github.com/Turfjs/turf/pull/1043 - Author @stevage)
@turf/shortest-path
][shortest-path]Returns the shortest path from start to end without colliding with any feature in obstacles (PR https://github.com/Turfjs/turf/pull/956 - Author @stebogit)
@turf/boolean-parallel
][boolean-parallel]Boolean-Parallel returns True if each segment of line1
is parallel to the correspondent segment of line2
(PR https://github.com/Turfjs/turf/pull/941 - Author @stebogit)
@turf/nearest-point-on-line
][nearest-point-on-line]Takes a {@link Point} and a {@link LineString} and calculates the closest Point on the (Multi)LineString. (PR https://github.com/Turfjs/turf/pull/939 - Author @stebogit)
Updates [@turf/unkink-polygon
][unkink-polygon] testing & added flattenEach
instead of using flatten
.
(PR https://github.com/Turfjs/turf/pull/889)
Add multi-geomtry support to @turf/line-split
(PR https://github.com/Turfjs/turf/pull/1078)
Improve @turf/meta
lineEach
method to provide properties, id and bbox
(PR https://github.com/Turfjs/turf/pull/1010)
Fixes @turf/helpers
earth radius variable
(PR https://github.com/Turfjs/turf/pull/1012)
Fixes @turf/polygon-tangents
bug
(PR https://github.com/Turfjs/turf/pull/1058)
Fixes @turf/line-chunk
bug when the number of segments is integer
(PR https://github.com/Turfjs/turf/pull/1046)
Fixes segmentEach
and segmentReduce
methods in @turf/meta
to ensure something is returned
(PR https://github.com/Turfjs/turf/pull/968)
Object
:Before
var from = [-75.343, 39.984];
var to = [-75.534, 39.123];
var units = 'miles';
var distance = turf.distance(from, to, units);
After
var from = [-75.343, 39.984];
var to = [-75.534, 39.123];
var options = {units: 'miles'};
var distance = turf.distance(from, to, options);
@turf/random
PR https://github.com/Turfjs/turf/issues/994@turf/idw
Issue https://github.com/Turfjs/turf/issues/887@turf/point-grid/hex/square/triangle
PR https://github.com/Turfjs/turf/pull/1029@turf/inside
=> @turf/boolean-point-in-polygon
https://github.com/Turfjs/turf/issues/860#issuecomment-317216235@turf/within
=> @turf/points-within-polygon
https://github.com/Turfjs/turf/issues/860#issuecomment-317216235@turf/bezier
=> @turf/bezier-spline
Issue https://github.com/Turfjs/turf/issues/661@turf/nearest
=> @turf/nearest-point
https://github.com/Turfjs/turf/pull/858#issuecomment-317197295@turf/point-on-line
=> @turf/nearest-point-on-line
https://github.com/Turfjs/turf/pull/858#issuecomment-317197295@turf/lineDistance
=> @turf/length
https://github.com/Turfjs/turf/issues/860#issuecomment-317229869@turf/helpers
radians2degrees
=> radiansToDegrees
degrees2radians
=> degreesToRadians
distanceToDegrees
=> lengthToDegrees
distanceToRadians
=> lengthToRadians
radiansToDistance
=> radiansToLength
bearingToAngle
=> bearingToAzimuth
convertDistance
=> convertLength
FAQs
turf meta module
The npm package @turf/meta receives a total of 967,818 weekly downloads. As such, @turf/meta popularity was classified as popular.
We found that @turf/meta demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.