Skip to main content
Version: 7.0.0

lineToPolygon

Description

Converts (Multi)LineString(s) to Polygon(s).

Parameters

NameTypeDescription
linesFeatureCollection | Feature<LineString | MultiLineString>Features to convert
options?ObjectOptional parameters (default {})
options.properties?Objecttranslates GeoJSON properties to Feature (default {})
options.autoComplete?booleanauto complete linestrings (matches first & last coordinates) (default true)
options.orderCoords?booleansorts linestrings to place outer ring at the first position of the coordinates (default true)
options.mutate?booleanmutate the original linestring using autoComplete (matches first & last coordinates) (default false)

Returns

Examples

var line = turf.lineString([
[125, -30],
[145, -30],
[145, -20],
[125, -20],
[125, -30],
]);

var polygon = turf.lineToPolygon(line);

Installation

$ npm install @turf/line-to-polygon

import { lineToPolygon } from "@turf/line-to-polygon";
const result = lineToPolygon(...);
$ npm install @turf/turf

import * as turf from "@turf/turf";
const result = turf.lineToPolygon(...);