Ring (boundary) directions are needed to prevent ambiguities for geographic coordinate systems that cover a finite surface, since the boundary would define two areas, one left and one right of the boundary along it's direction. Determining which of those two areas is the bigger one is possible, but still leaves the ambiguity.
Here is an overview on outer ring directions of polygons in various formats by their specifications:
- Simple Feature Access (ISO 19125-1)
also used in WKT/GML/KML and various SQL implementations:
- exterior rings: counter-clockwise
- interior rings (holes): clockwise direction.
A Polygon is a planar Surface defined by 1 exterior boundary and 0 or more interior boundaries. Each interior boundary defines a hole in the Polygon. [...]
The exterior boundary LinearRing defines the “top” of the surface which is the side of the surface from which the exterior boundary appears to traverse the boundary in a counter clockwise direction. The interior LinearRings will have the opposite orientation, and appear as clockwise when viewed from the “top”... Simple Feature Access specs
In most implementations the order of rings in a POLYGON is important (as opposed to shapefiles)
For a polygon with holes, its first subelement is its exterior ring, its second subelement is its first interior ring, its third subelement is its second interior ring, and so on. Oracle Spatial
Deeper nestings, aka island-in-a-lake-on-an-island-... have to be represented as MultiPolygons (see figure 2.10 (4)), since there can be only one exterior border and deeper nestings than interior rings are not defined.
A polygon consists of one or more rings. A ring is a connected sequence of four or more points that form a closed, non-self-intersecting loop. A polygon may contain multiple outer rings. The order of vertices or orientation for a ring indicates which side of the ring is the interior of the polygon. The neighborhood to the right of an observer walking along the ring in vertex order is the neighborhood inside the polygon. Vertices of rings defining holes in polygons are in a counterclockwise direction. Vertices for a single, ringed polygon are, therefore, always in clockwise order. [...]
The order of rings in the points array is not significant. ESRI Whitepaper
Since multiple outer boundaries are allowed island-in-a-lake-on-an-island configurations are possible with this polygon definition. Topologically the island in a lake would be just another clockwise outer ring. Effectively this makes an ESRI Shapefile Polygon a Simple Feature MultiPolygon
If you don’t order the points correctly you’ll just have overlapping polygons. pyshp
NOTE: Original GeoJSON 2008 spec had no winding order enforced
- winding order: exterior ring is counter-clockwise (right hand rule)
- interior rings are clockwise
- order of rings is important:
For Polygons with multiple rings, the first must be the exterior ring and any others must be interior rings or holes. GeoJSON spec
- TopoJSON: forces exterior rings clockwise by default
The mathematical reasoning on why winding orders of nested rings alternate is, that calculating the area with the shoelace formula (visual explanation) computes signed areas depending on the ring direction.
In general nested rings (interior boundaries) are considered holes and have the alternate direction of the outer ring. Their contributing signed area value is negative. Where as outer rings are positive. The total area of all ring features is the sum of all signed areas.
As implemented by ESRI see this Knowledge Base entry: What algorithm is used by ArcGIS to determine a polygon's area?
Open ends of letterforms interpreted as arrows:
- Shapefile: S → ᔑ → ↻
- Simple Features: e → ᘓ (winding outwards cc-wise) → ↺
- GeoJSON: G (stem of G is arrow) → ↺