What Does Flatten Do?
Flattening converts Multi-geometry features into individual single-geometry features. A MultiPolygon with three parts becomes three separate Polygon features. A MultiLineString becomes individual LineStrings. Each resulting feature retains the properties of the original.
Before and After
| Input Type | Output Type |
|---|---|
| MultiPoint | Multiple Point features |
| MultiLineString | Multiple LineString features |
| MultiPolygon | Multiple Polygon features |
| GeometryCollection | Individual geometry features |
| Point / LineString / Polygon | Unchanged (already flat) |
When to Flatten GeoJSON
- Preparing data for tools that only accept single-type geometries
- Getting an accurate feature count of individual shapes
- Styling individual polygon parts differently on a map
- Splitting multi-part country boundaries (like island nations) into separate features
- Enabling per-part area or length calculations
The reverse of flattening is collecting single features into Multi-geometries, which can be done with the dissolve tool.
Try It
Paste this MultiPolygon representing two separate parks. The flatten tool will split it into two individual Polygon features, each carrying the original properties:
GeoJSON{
"type": "Feature",
"properties": { "type": "park", "city": "New York" },
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[[[-73.9712, 40.7831], [-73.9712, 40.7644], [-73.9490, 40.7644],
[-73.9490, 40.7831], [-73.9712, 40.7831]]],
[[[-73.9973, 40.7308], [-73.9973, 40.7295], [-73.9950, 40.7295],
[-73.9950, 40.7308], [-73.9973, 40.7308]]]
]
}
}The output is a FeatureCollection with two Polygon features. Each one keeps {"type": "park", "city": "New York"} as its properties, but holds only a single polygon ring:
GeoJSON{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": { "type": "park", "city": "New York" },
"geometry": {
"type": "Polygon",
"coordinates": [[[-73.9712, 40.7831], [-73.9712, 40.7644],
[-73.9490, 40.7644], [-73.9490, 40.7831], [-73.9712, 40.7831]]]
}
},
{
"type": "Feature",
"properties": { "type": "park", "city": "New York" },
"geometry": {
"type": "Polygon",
"coordinates": [[[-73.9973, 40.7308], [-73.9973, 40.7295],
[-73.9950, 40.7295], [-73.9950, 40.7308], [-73.9973, 40.7308]]]
}
}
]
}How It Works
The flatten algorithm iterates over each Feature in the input. When it encounters a Multi-type geometry, it extracts each component geometry and wraps it in its own Feature with a copy of the original properties. Single-type geometries (Point, LineString, Polygon) pass through unchanged. GeometryCollections are decomposed into one Feature per member geometry.
Flattening is especially useful before running tools that operate on individual features, such as the area calculator or the centroid calculator. For details on Multi-type geometries and when they are used, see the GeoJSON Specification Guide.