What is @turf/combine?
@turf/combine is a module from the Turf.js library that allows you to combine multiple GeoJSON features into a single feature collection. This is particularly useful for merging multiple geometries into a single collection for easier manipulation and analysis.
What are @turf/combine's main functionalities?
Combine Multiple Features
This feature allows you to combine multiple GeoJSON features (points, lines, polygons) into a single feature collection. The code sample demonstrates combining two points and a line into one feature collection.
const turf = require('@turf/turf');
const point1 = turf.point([0, 0]);
const point2 = turf.point([2, 2]);
const line = turf.lineString([[1, 1], [3, 3]]);
const combined = turf.combine(turf.featureCollection([point1, point2, line]));
console.log(JSON.stringify(combined));
Other packages similar to @turf/combine
geojson-merge
The geojson-merge package allows you to merge multiple GeoJSON files into one. It is similar to @turf/combine in that it combines multiple GeoJSON features, but it is more focused on merging files rather than individual features.
geojson-flatten
The geojson-flatten package is used to flatten nested GeoJSON geometries into a single-level feature collection. While @turf/combine focuses on combining features, geojson-flatten is useful for simplifying complex nested structures.
geojson-utils
The geojson-utils package provides a variety of utility functions for working with GeoJSON data, including combining features. It offers a broader range of functionalities compared to @turf/combine, which is specialized for combining features.
@turf/combine
combine
Combines a FeatureCollection of Point, LineString, or Polygon features
into MultiPoint, MultiLineString, or MultiPolygon features.
Parameters
Examples
var fc = turf.featureCollection([
turf.point([19.026432, 47.49134]),
turf.point([19.074497, 47.509548])
]);
var combined = turf.combine(fc);
var addToMap = [combined]
Returns FeatureCollection<(MultiPoint | MultiLineString | MultiPolygon)> a FeatureCollection of corresponding type to input
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 single module individually:
$ npm install @turf/combine
Or install the all-encompassing @turf/turf module that includes all modules as functions:
$ npm install @turf/turf