turf.polygonToLine
What is turf.polygonToLine?
turf.polygonToLine takes a Polygon or MultiPolygon and returns its boundary as a LineString, MultiLineString, or a FeatureCollection of lines — including interior rings when present.
turf.polygonToLine(polygon, options?) → Feature<LineString | MultiLineString> | FeatureCollection<LineString>Options include:
properties— output feature properties
When would you use turf.polygonToLine?
Use turf.polygonToLine to style polygon outlines separately from fill on MapLibre (stroke the line layer, fill the polygon), to compute perimeter with turf.length, or to feed the ring into line-level operations like turf.lineSplit or turf.along.
In Node.js, it is a useful preprocessing step when you need to index just the boundary of a polygon — for example, building fast edge-based nearest-edge queries or exporting cadastral boundaries as line data.
undefinedFAQs
What does the output look like for a polygon with holes?
A polygon with holes produces a MultiLineString whose first part is the exterior ring and subsequent parts are each interior ring.
How do I install just polygonToLine?
npm install @turf/polygon-to-line. It depends on @turf/helpers and @turf/invariant.
Does it preserve properties?
Yes — the input feature's properties are copied onto the output by default, or you can override them via options.properties.
Can I convert it back?
Yes — pass the result to turf.lineToPolygon. The round trip is lossless for simple polygons (no holes). For polygons with holes, reconstruct carefully because lineToPolygon takes a single ring.