LineSmootherMcMaster

Smooths lines with the sliding averaging of McMaster: each vertex moves towards the mean position of the vertices around it. It removes the small wiggles of the lines, as those of the contours or of the borders extracted from a raster, keeping their general course and their ends.

Details

Each vertex moves to (1 - slide) x its position + slide x the average position of the look ahead vertices centered on it: with a slide of 1 it goes to the average, with 0 it stays. An even look ahead is increased by one. The window is a number of vertices, not a distance, so on lines with unevenly spaced vertices the densify interval, applied before the smoothing, makes it a length as well: the window is then about look ahead x interval long. Lines with fewer vertices than four times the look ahead use a window of a fifth of their vertices, and lines with fewer than 10 vertices are not smoothed.

The first and the last half window of vertices stay in place, so the lines keep their ends and stay connected to each other. Closed lines are smoothed across their closing vertex.

The lines not longer than the limit are not smoothed. Among them, the closed ones and the ones not touching another line at their ends are removed, as the small rings and the isolated bits of a vectorized raster. The optional simplification, after the smoothing, drops the vertices closer than its tolerance to the line, without changing the topology.

Parameters

Smooths lines with the sliding averaging of McMaster: each vertex moves towards the average of the vertices around it.

Toolbox folder: Vector Processing
Status: Certified
Keywords: Smoothing, Vector, Generalization
Authors: Andrea Antonello
Class: org.hortonmachine.modules.LineSmootherMcMaster

Inputs

Parameter

Type

Unit

Default

Description

inVector

vector file

The vector containing the lines to be smoothed.

pLookahead

int

7

The number of vertices averaged for each vertex, an odd number (default = 7).

pLimit

int

0

The length up to which the lines are not smoothed: of them, the closed ones and the ones not connected to other lines are removed.

pSlide

double

0.9

How far each vertex moves towards the average, from 0 (it stays) to 1 (it goes to the average).

pDensify

Double

The optional maximum distance between the vertices, added before the smoothing.

pSimplify

Double

The optional tolerance of a simplification after the smoothing.

Outputs

Parameter

Type

Unit

Description

outVector

output file

The vector with smoothed features.

References

  • McMaster, R. B. (1989). The integration of simplification and smoothing algorithms in line generalization. Cartographica, 26(1), 101-121.

Example

The example smooths the contour lines of ContourExtractor, extracted from the sample elevation model, on a window of about 80 m:

import org.hortonmachine.modules.LineSmootherMcMaster

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

var smoother = new LineSmootherMcMaster()
// the contour lines of ContourExtractor, with a vertex for each cell crossed
smoother.inVector = folder + "contours.shp"
// a vertex every 2 m, the average of 41 vertices: a window of about 80 m
smoother.pDensify = 2.0
smoother.pLookahead = 41
smoother.pSlide = 1.0
// and then fewer vertices again
smoother.pSimplify = 0.5
smoother.outVector = folder + "contours_mcmaster.shp"
smoother.process()

A detail of the smoothed lines in red, under the original ones in blue: the small turns of the contours, that follow the cells of the elevation model, are gone:

A detail of the contour lines smoothed by the sliding averaging, under the original ones

The LineSmootherJaitools smooths instead with curves through the vertices.