turf.multiPolygon
What is turf.multiPolygon?
turf.multiPolygon wraps a deeply nested coordinate array into a valid Feature<MultiPolygon>. Each polygon in the MultiPolygon can itself have an outer ring plus any number of inner holes.
turf.multiPolygon(coordinates, properties?, options?) → Feature<MultiPolygon>Options include:
bbox— bounding box[minX, minY, maxX, maxY]id— identifier for the feature
When would you use turf.multiPolygon?
Use turf.multiPolygon for any feature whose shape is fundamentally multipart — countries with islands, a chain of retail-store catchment areas under one brand, or the output of turf.union/turf.difference when the result has multiple disjoint pieces.
Admin boundary data (e.g. Natural Earth countries, US census tracts split by water) almost always arrives as MultiPolygon. When you receive such data, keep it as MultiPolygon rather than flattening — many Turf boolean and overlay functions handle MultiPolygon natively.
1const countryLike = turf.multiPolygon(
2 [
3 [[[0, 0], [2, 0], [2, 2], [0, 2], [0, 0]]],
4 [[[3, 3], [5, 3], [5, 5], [3, 5], [3, 3]]]
5 ],
6 { name: 'Two Islands' }
7);FAQs
How do I install Turf.js to use this function?
Install npm install @turf/helpers and import with import { multiPolygon } from '@turf/helpers', or via the umbrella @turf/turf bundle.
What is the nesting depth of the coordinates argument?
Four levels: MultiPolygon → Polygon → Ring → Position. The outermost array lists polygons, each polygon is an array of rings (first ring is outer, others are holes), each ring is an array of positions, each position is [lng, lat].
Does turf.multiPolygon close each ring automatically?
No. The first and last position of every ring must be identical, matching the GeoJSON spec. If you build rings programmatically, append the first coordinate at the end.
Should I prefer Polygon or MultiPolygon when I have just one polygon?
Prefer Polygon for a single shape — it is simpler and more widely supported. Use MultiPolygon only when you genuinely have multiple disjoint pieces, or when you need a consistent schema for a dataset where some records have multiple parts.