reverse_polygon
Geometric functions > reverse_polygon
syntax
- reverse_polygon(polygon_data_item)
description
reverse_polygon(polygon_data_item) reverses the winding order of every ring in each element of the polygon_data_item, resulting in a data item with the same domain unit and values unit as the argument.
Each ring is reversed in place: the layout of the point sequence is not changed. That matters for multi-polygons, where the parts and holes of one element share a single point sequence and are strung together with backtrack points. Reversing the sequence as a whole would break that structure, because the reader recognises a new ring where a point repeats the ring’s own first point. Reversing ring by ring cannot: a closed ring p0 p1 … pk p0 reverses to p0 pk … p1 p0, so every ring delimiter and every backtrack point stays exactly where it was.
The operator changes no coordinates and is exactly its own inverse, so reverse_polygon(reverse_polygon(g)) equals g and area(reverse_polygon(g)) equals -area(g). It has no geometry-library dependency and works for every point value type, integer coordinates included.
Use it when a whole layer is known to be flipped — the usual cause is a source that lists coordinates in latitude/longitude order. When only part of a feature is flipped, reversing does not help; use fix_winding_order instead, which derives the ring roles from their nesting.
Note that reverse is a different, unrelated function: it reverses the order of the values of an attribute, not the points within a geometry.
applies to
- attribute polygon_data_item with a point value type and composition type polygon
conditions
The composition type of the polygon_data_item needs to be polygon.
since version
20.18
example
attribute<rdc> geometry_fixed (poly, district) := reverse_polygon(district/geometry);
| district/geometry | area(district/geometry, m2) | area(geometry_fixed, m2) |
|---|---|---|
| {5: xy(0; 0) …} | -1003100 | 1003100 |