cartagen.remove_flat_vertices#
- remove_flat_vertices(geom, tolerance=5.0)#
Removes flat vertices from a geometry.
A vertex is considered flat when the interior angle it forms with its two neighbours is close to 180°, meaning the three points are nearly collinear and the vertex brings no geometric information. Removing such vertices simplifies the geometry without altering its shape.
- Parameters:
geom (
LineString,MultiLineString,Polygon,MultiPolygon, orLinearRing) – The geometry to simplify.tolerance (
float, optional) – Tolerance in degrees. A vertex whose interior angle deviates from 180° by less than or equal to this value is removed. Defaults to 0.6°.
- Returns:
LineString,MultiLineString,Polygon,MultiPolygon, orLinearRing– A simplified geometry of the same type as the input.
Examples
>>> polygon = Polygon([(0, 0), (0.5, 0), (1, 0), (1, 1), (0, 1)]) >>> remove_flat_vertices(polygon) <POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))>