Turf.jsHelper

turf.geometryCollection

What is turf.geometryCollection?

turf.geometryCollection creates a GeoJSON Feature<GeometryCollection> from an array of heterogeneous geometries — points, lines, polygons, and their multi-variants mixed together inside a single geometry field.

JavaScript
turf.geometryCollection(geometries, properties?, options?) → Feature<GeometryCollection>

Options include:

  • bbox — bounding box [minX, minY, maxX, maxY]
  • id — identifier for the feature

When would you use turf.geometryCollection?

Reach for turf.geometryCollection when you have one logical record whose geometry is best represented as several parts of different types — for example a trail system record that owns both the trailhead Point and the trail LineString, or a building footprint (Polygon) paired with its entrance markers (MultiPoint).

In practice, most web map renderers and spatial databases handle FeatureCollection better than GeometryCollection. Use turf.featureCollection if your features have independent properties, and reserve geometryCollection for the cases where the geometries share a single properties object.

JavaScript
1const point = turf.point([-122.42, 37.77]).geometry;
2const line = turf.lineString([[-122.42, 37.77], [-122.41, 37.78]]).geometry;
3const gc = turf.geometryCollection([point, line], { route: 'walking' });

FAQs

How do I install Turf.js to use this function?

Install with npm install @turf/helpers and import as import { geometryCollection } from '@turf/helpers', or use the full @turf/turf bundle.

Do all Turf functions accept a GeometryCollection?

No. Some functions (e.g. turf.area, turf.bbox) handle GeometryCollection but many spatial predicates and transformations operate only on specific geometry types. Test before relying on it or flatten with turf.flatten first.

Can a GeometryCollection contain another GeometryCollection?

The GeoJSON spec strongly discourages nested GeometryCollections. Turf follows the spec — pass primitive geometries only (Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon).

What is the difference between GeometryCollection and FeatureCollection?

A FeatureCollection is an array of independent Features, each with its own properties. A GeometryCollection is one Feature whose geometry happens to be a list of heterogeneous geometries sharing a single set of properties. Choose based on whether the parts share metadata.