turf.coordAll
What is turf.coordAll?
turf.coordAll walks any GeoJSON object and returns a flat array of every coordinate position it contains, regardless of the original geometry type or nesting.
turf.coordAll(geojson) → Array<Position>When would you use turf.coordAll?
Use turf.coordAll when you need to compute something over every vertex of a GeoJSON — the centroid of all vertices, the extent (simpler than turf.bbox for quick checks), or a deduplicated list of locations across mixed geometry types. It is also the quickest way to dump coordinates into a non-GeoJSON format such as a CSV export.
Because it flattens everything into one array, all structural information (which feature, which ring, which line) is lost. If you need to preserve structure, reach for turf.coordEach or turf.coordReduce with an index callback.
1const fc = turf.featureCollection([pointA, polygonB, lineC]);
2const allPositions = turf.coordAll(fc);
3console.log(`Total vertices: ${allPositions.length}`);FAQs
How do I install Turf.js to use this function?
Install the meta package for tree-shaking: npm install @turf/meta, then import { coordAll } from '@turf/meta'. It is also part of the umbrella @turf/turf bundle.
Does coordAll deduplicate coordinates?
No. If a vertex is shared between two features or a ring closes back on itself, the repeated position appears multiple times. Apply your own dedupe logic if needed.
Does it walk into GeometryCollections?
Yes. coordAll recurses into GeometryCollection, MultiPolygon, MultiLineString, MultiPoint — every position at any depth ends up in the flat array.
When should I use coordEach instead?
Use turf.coordEach when you need the index or context of each vertex (feature index, geometry index, ring index, position index) as you iterate. coordAll is a convenience for the common case of just wanting the list.