cartagen.remove_flat_vertices

cartagen.remove_flat_vertices#

remove_flat_vertices(polygon, tolerance=8.0)#

Removes flat vertices from a polygon.

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 polygon without altering its shape.

Parameters:
  • polygon (Polygon) – The polygon 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:

Polygon

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))>

(Source code)

../_images/remove_flat_vertices.png