cartagen.smooth_catmull_rom

cartagen.smooth_catmull_rom#

smooth_catmull_rom(geometry, subdivisions=10, alpha=0.5)#

Smooth a line or polygon and preserve vertexes.

This algorithm was proposed by Catmull and Rom [1], this is the version proposed by Barry and Goldman [2] that makes use of the de Boor’s algorithm for evaluating spline curves in B-spline form.

Catmull-Rom splines are a family of cubic interpolating splines that pass through all control points. The alpha parameter controls the type of parameterization: 0 for uniform, 0.5 for centripetal (default), and 1 for chordal. Centripetal parameterization avoids cusps and self-intersections.

Accept Multi geometries. If a polygon is provided, it also applies the smoothing to its holes using the same parameters.

This implementation is a translation of the C++ implementation available here.

Parameters:
  • geometry (LineString, MultiLineString, Polygon, MultiPolygon, LinearRing) – The line or polygon to smooth. The spline passes through all original vertices.

  • subdivisions (int, optional) – Number of interpolated points between each pair of control points. Default is 10. Higher values produce smoother curves.

  • alpha (float, optional) –

    Parameterization type. Default is 0.5 (centripetal):

    • 0.0: uniform parameterization

    • 0.5: centripetal parameterization (recommended, prevents loops)

    • 1.0: chordal parameterization

Returns:

LineString, Polygon, MultiLineString, MultiPolygon, LinearRing – Smoothed geometry of the same type as input.

See also

smooth_chaikin

Smooth a line or polygon by cutting corners.

References

Examples

>>> line = LineString([(0, 0), (1, 1), (2, 0), (3, 1)])
>>> smooth_catmull_rom(line, alpha=0.5, subdivisions=10)
<LINESTRING (0 0, 0.1 0.12, ... 3 1)>
>>> polygon = Polygon([(0, 0), (0, 2), (2, 2), (2, 0), (0, 0)])
>>> smooth_catmull_rom(polygon, alpha=0.5, subdivisions=20)
<POLYGON ((0 0.1, ... 0 0.1))>

(Source code)

../_images/smooth_catmull_rom.png