Skip to content

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, default 130), buffer_distance (m, default 2.0)
  • Outputs: smoothed centerline vector with the input attributes and line order

Method summary

  1. Read the lines and send each line to a worker (smooth_worker in beratools/modules/mapping/smooth_centerline.py).
  2. Merge a MultiLineString with linemerge; parts that stay separate are smoothed one by one.
  3. 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.
  4. For a vertex with an angle below angle_threshold, cut the corner (_cut_corner):
  5. Intersect the line with a circle of radius buffer_distance around the vertex.
  6. Take the points where the line enters and leaves the circle.
  7. Replace the stretch between them with a straight chord; the line before and after keeps its vertices.
  8. Skip the vertex right after a cut corner, so two neighbouring vertices aren't both cut.
  9. 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_distance is in metres.
  • buffer_distance is small compared with the segment lengths and the footprint width.

Edge cases

  • Lines with fewer than three vertices, empty lines and buffer_distance <= 0 are 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_distance of a line end cuts the line from that end.