cartagen.smooth_chaikin#
- smooth_chaikin(geometry, iterations=3, keep_ends=True)#
Smooth a line or polygon by cutting corners.
This algorithm was proposed by Chaikin [1] and this version makes use of the equivalent multi-step algorithm introduced by Wu et al. [2]. It is a simple subdivision scheme that repeatedly cuts corners of a line or polygon. Each iteration doubles the number of vertices and produces a smoother curve that converges to a quadratic B-spline.
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.iterations (
int, optional) – Number of subdivision iterations (k parameter). Default is 3. Each iteration doubles the number of vertices (2^k subdivisions per segment).keep_ends (
bool, optional) – Whether to keep the original endpoints fixed for open lines. Default is True. For closed geometries, this parameter is ignored and corners are always cut.
- Returns:
LineString,Polygon,MultiLineString,MultiPolygon,LinearRing– Smoothed geometry of the same type as input.
Warning
Note that the algorithm (roughly) doubles the amount of nodes at each iteration, therefore care should be taken when selecting the number of iterations.
See also
smooth_catmull_romSmooth a line or polygon and preserve vertexes.
References
Examples
>>> line = LineString([(0, 0), (1, 1), (2, 0), (3, 1)]) >>> smooth_chaikin(line, iterations=2, keep_ends=True) <LINESTRING (0 0, 0.3 0.3, ... 3 1)>
>>> polygon = Polygon([(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)]) >>> smooth_chaikin(polygon, iterations=2) <POLYGON ((0.1 0.2, ... 0.1 0.2))>