Turf.jsFeature Conversion

turf.flatten

What is turf.flatten?

turf.flatten takes any GeoJSON input and returns a FeatureCollection where every MultiPoint, MultiLineString, and MultiPolygon has been split into individual Point, LineString, and Polygon features. Single-geometry features pass through unchanged.

JavaScript
turf.flatten(geojson) → FeatureCollection

When would you use turf.flatten?

Use turf.flatten before any operation that expects single-part geometries — turf.tesselate, some boolean checks, or styling workflows that want one feature per part on a MapLibre layer. It is the easy fix for "this function does not accept MultiPolygon".

In Node.js ETL, flattening is a common step when exporting to databases or formats that prefer normalised geometry types (e.g. one row per ring in a PostGIS table).

Code
undefined

FAQs

Do flattened features inherit the parent properties?

Yes — each split feature copies the source feature's properties. If you need per-part attribution, assign it after flattening.

How do I install just flatten?

npm install @turf/flatten. It depends on @turf/meta and @turf/helpers.

Does the order of output parts match the input?

Yes — parts are emitted in the order they appeared in the Multi coordinates array, so index i in the output corresponds to the i-th part of the input Multi geometry.

How is it different from turf.explode?

turf.flatten splits multi-geometries into features of the same type (Polygon parts → Polygons). turf.explode decomposes everything into points — it operates at the vertex level.