itacart.geometry.canonicalize_rings

itacart.geometry.canonicalize_rings(rings)[source]

Normalise rings to a single spelling per geometry.

Rings are rotated to their minimum lexicographic cyclic rotation, so the same ring starting at a different vertex canonicalises to the same sequence. Rotation applies to closed rings only; LINESTRING is directional and is left as given, which is why this function takes rings and not lines.

Winding is not touched. A ring’s direction distinguishes an exterior from a hole and is information the caller put there; rotating is a change of spelling, reversing would be a change of meaning. Ordering the rings themselves is likewise the caller’s, since the exterior comes first by contract.

The ordering key is the index string. Two cells of the same resolution have strings of the same length, so string order is a total order over the ring and the rotation is unique.

This is what makes a geometry content-addressable, and therefore what makes hashing it meaningful.

Provenance: itacart_core/geometry_blob.py (_canonicalize_polygon_rings, _booth_min_rotation).

Parameters:

rings (list[list[str]]) – Rings as lists of atomic index strings, exterior first.

Return type:

list[list[str]]

Returns:

The canonicalised rings, in input order.