Smooth Centerline — Algorithm Notes
Related user page: Smooth Centerline
Purpose
Cut off sharp corners of centerlines and leave every other vertex unchanged. Ported from SegLine (src/utils/smooth_centerline.py) by Irina Terentieva.
Inputs and outputs
- Inputs: centerline vector,
angle_threshold(degrees, default130),buffer_distance(m, default2.0) - Outputs: smoothed centerline vector with the input attributes and line order
Method summary
- Read the lines and send each line to a worker (
smooth_workerinberatools/modules/mapping/smooth_centerline.py). - Merge a
MultiLineStringwithlinemerge; parts that stay separate are smoothed one by one. - Walk the interior vertices of the line and compute the interior angle at each one from its two neighbours (
vertex_interior_angle).180°is straight, smaller is sharper. - For a vertex with an angle below
angle_threshold, cut the corner (_cut_corner): - Intersect the line with a circle of radius
buffer_distancearound the vertex. - Take the points where the line enters and leaves the circle.
- Replace the stretch between them with a straight chord; the line before and after keeps its vertices.
- Skip the vertex right after a cut corner, so two neighbouring vertices aren't both cut.
- Restore the input order, count the changed lines and write the output.
The core logic is smooth_sharp_vertices in beratools/modules/mapping/algo_geometry.py.
Comparison with other smoothing
- Centerline's Smooth LCP smooths every vertex of the least-cost path.
- Centerline's Simplify Centerline (
geo-simplify reduce-bend) reduces bends along the whole line. - Smooth Centerline changes only the sharp vertices and keeps the rest of the line exactly.
Assumptions
- Lines are in a projected CRS, so
buffer_distanceis in metres. buffer_distanceis small compared with the segment lengths and the footprint width.
Edge cases
- Lines with fewer than three vertices, empty lines and
buffer_distance <= 0are returned unchanged. - A corner is left as is when the line crosses the circle more than once (the intersection isn't a single line), for example where the line loops back near the vertex.
- Angles are measured on the input vertices, so a corner next to one already cut is judged by its original shape.
- A vertex within
buffer_distanceof a line end cuts the line from that end.