Turf.jsFeature Conversion

turf.polygonize

What is turf.polygonize?

turf.polygonize takes a FeatureCollection<LineString | MultiLineString> of fully noded (topologically clean) lines and returns a FeatureCollection<Polygon> formed by closed rings of those lines. It is a JavaScript port of JTS/PostGIS's Polygonize.

JavaScript
turf.polygonize(lines) → FeatureCollection<Polygon>

When would you use turf.polygonize?

Use turf.polygonize to rebuild polygon layers from line data — for example, constructing cadastral parcels from survey lines, recovering administrative regions from boundary edges, or turning a road network's city blocks into polygons. It is a powerful step in data-preparation pipelines that take CAD or survey exports and need polygonal output.

A typical pattern in Node.js is: load line network → ensure lines are noded (cut at intersections using turf.lineIntersect and turf.lineSplit) → call turf.polygonize → get block polygons. The noding step is non-negotiable; malformed input produces invalid or missing polygons.

Code
undefined

FAQs

Do my lines need to be noded?

Yes. turf.polygonize expects every line endpoint to coincide exactly with another line's endpoint; otherwise the topology is broken. Use turf.lineIntersect plus turf.lineSplit or run through a pre-processing step like @mapbox/polyline-split-at-intersections to node the network first.

How do I install just polygonize?

npm install @turf/polygonize. It depends on @turf/helpers, @turf/invariant, and @turf/meta.

Does it handle dangling lines?

Dangling lines (edges not part of any ring) are dropped from the output. Only lines that participate in a closed ring produce polygons.

What performance should I expect?

Polygonising a network is O(n) in edges with overhead for ring detection. For tens of thousands of edges it remains tractable in Node.js. For production-scale networks, consider a PostGIS ST_Polygonize round trip.