LinesPolygonizer

Builds polygons from lines, as the parcels of a drawing whose borders were traced as single lines. In the default mode, faces, every area closed by the lines becomes a polygon, also where the lines cross without a shared vertex. In the join mode the lines of each group are chained into a single polygon, which closes small gaps between them. The id of the polygons can be taken from points that lie in them, as the labels of a drawing.

Details

In the faces mode the lines are first noded, cut where they cross, so lines that cross without sharing a vertex still close a face. Every face the network encloses becomes a polygon, also the ones between other faces: a line that closes onto itself makes a polygon, a line that ends in nothing (a dangle) or only connects two faces (a cut edge) does not. The number of the lines that were not used is reported in the log.

In the join mode the lines of each group, all the lines when no group field is given, are chained into one ring: from the end of a line the chain goes on with the line that has the nearest end, reversing it if needed, and the last line is joined to the first. Gaps between the lines are closed with a straight segment, which suits outlines digitized in pieces. The groups whose ring crosses itself are reported and left out.

The id of a polygon is taken from the point of the points layer that lies in it, if a points layer is given, else from the group in the join mode, else it is a progressive number from 1. Polygons with no point get no id.

Parameters

Builds polygons from lines, as the faces the lines enclose or as one polygon for each group of lines.

Toolbox folder: Vector Processing
Status: Certified
Keywords: Vector, Polygonize
Authors: Antonio Falciano, Andrea Antonello
Class: org.hortonmachine.modules.LinesPolygonizer

Inputs

Parameter

Type

Unit

Default

Description

inMap

vector file

The lines to polygonize.

pMode

String

faces

How to build the polygons: faces, the areas enclosed by the lines, or join, one polygon chaining the lines of each group. Allowed values: faces, join.

fGroup

String

The field of the lines that groups them into polygons in the join mode (optional, all the lines make one polygon if not set).

inPoints

vector file

The points whose attribute gives the id of the polygon they lie in (optional).

fId

String

The field of the points with the id of the polygons (necessary if the points are given).

fNewId

String

id

The field of the polygons for the id.

Outputs

Parameter

Type

Unit

Description

outMap

output file

The polygons.

Example

The example builds the elevation belts of the basin of ExtractBasin. It takes the contour lines cut to the basin by VectorClipper and adds the outline of the basin, made into a line by VectorReshaper and merged with VectorMerger:

import org.hortonmachine.modules.LinesPolygonizer
import org.hortonmachine.modules.VectorMerger
import org.hortonmachine.modules.VectorReshaper

// the folder with the elevation model: change it to yours
var folder = "/data/flanginec/"

// the outline of the basin of ExtractBasin as a line, with the same fields as the contours
var reshaper = new VectorReshaper()
reshaper.inVector = folder + "basin.shp"
reshaper.pCql = """the_geom=boundary(the_geom)
value=0.0"""
reshaper.pRemove = "area"
reshaper.outVector = folder + "basin_outline.shp"
reshaper.process()

// together with the contour lines cut to the basin by VectorClipper
var merger = new VectorMerger()
merger.inVector1 = folder + "contours_basin.shp"
merger.inVector2 = folder + "basin_outline.shp"
merger.outVector = folder + "basin_lines.shp"
merger.process()

// the faces between the contours and the divide: the elevation belts of the basin
var polygonizer = new LinesPolygonizer()
polygonizer.inMap = folder + "basin_lines.shp"
polygonizer.fNewId = "belt"
polygonizer.outMap = folder + "basin_belts.shp"
polygonizer.process()

The 10 contour lines and the divide close 11 belts. Their areas sum up to the 1.89 km² of the basin. The lines are drawn in blue:

The elevation belts of the basin, each with its own color, between the contour lines

The belts are numbered in the order the polygonizer finds them, not by elevation. Without the divide, the contours would close no belt, since they end on the border of the basin.