shapely.orient_polygons#
- orient_polygons(geometry, *, exterior_cw=False, **kwargs)#
Enforce a ring orientation on all polygonal elements in the input geometry.
Forces (Multi)Polygons to use a counter-clockwise orientation for their exterior ring, and a clockwise orientation for their interior rings (or the oppposite if
exterior_cw=True
).Also processes geometries inside a GeometryCollection in the same way. Other geometries are returned unchanged.
Added in version 2.1.0.
- Parameters:
- geometryGeometry or array_like
Geometry or geometries to orient consistently.
- exterior_cwbool, default False
If True, exterior rings will be clockwise and interior rings will be counter-clockwise.
- **kwargs
See NumPy ufunc docs for other keyword arguments.
Examples
A polygon with both shell and hole having clockwise orientation:
>>> from shapely import Polygon, orient_polygons >>> polygon = Polygon( ... [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)], ... holes=[[(2, 2), (2, 4), (4, 4), (4, 2), (2, 2)]], ... ) >>> polygon <POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (2 2, 2 4, 4 4, 4 2, 2 2))>
By default, the exterior ring is oriented counter-clockwise and the holes clockwise:
>>> orient_polygons(polygon) <POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (2 2, 2 4, 4 4, 4 2, 2 2))>
Asking for the opposite orientation:
>>> orient_polygons(polygon, exterior_cw=True) <POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (2 2, 4 2, 4 4, 2 4, 2 2))>