What is @turf/meta?
@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.
What are @turf/meta's main functionalities?
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);
});
Other packages similar to @turf/meta
geojson-utils
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.
geolib
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.
geojson-extent
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.
@turf/meta
coordEach
Iterate over coordinates in any GeoJSON object, similar to
Array.forEach.
Parameters
layer
Object any GeoJSON objectcallback
Function a method that takes (value)excludeWrapCoord
[boolean] whether or not to include
the final coordinate of LinearRings that wraps the ring in its iteration.
Examples
var point = { type: 'Point', coordinates: [0, 0] };
coordEach(point, function(coords) {
});
coordReduce
Reduce coordinates 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 coordinates is unnecessary.
Parameters
layer
Object any GeoJSON objectcallback
Function a method that takes (memo, value) and returns
a new memomemo
Any the starting value of memo: can be any type.excludeWrapCoord
[boolean] whether or not to include
the final coordinate of LinearRings that wraps the ring in its iteration.
Returns Any combined value
propEach
Iterate over property objects in any GeoJSON object, similar to
Array.forEach.
Parameters
layer
Object any GeoJSON objectcallback
Function a method that takes (value)
Examples
var point = { type: 'Feature', geometry: null, properties: { foo: 1 } };
propEach(point, function(props) {
});
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 objectcallback
Function a method that takes (memo, coord) and returns
a new memomemo
Any the starting value of memo: can be any type.
Returns Any combined value
featureEach
Iterate over features in any GeoJSON object, similar to
Array.forEach.
Parameters
layer
Object any GeoJSON objectcallback
Function a method that takes (value)
Examples
var feature = { type: 'Feature', geometry: null, properties: {} };
featureEach(feature, function(feature) {
});
coordAll
Get all coordinates from any GeoJSON object, returning an array of coordinate
arrays.
Parameters
layer
Object any GeoJSON object
Returns Array<Array<Number>> coordinate position array
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