Skip to content

Commit

Permalink
Merge bfda9b4 into 84c5ad4
Browse files Browse the repository at this point in the history
  • Loading branch information
theroggy committed Feb 16, 2024
2 parents 84c5ad4 + bfda9b4 commit 0ded2b4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
25 changes: 25 additions & 0 deletions docs/geometry.rst
Expand Up @@ -173,3 +173,28 @@ specified, rounding precision will be disabled showing full precision.
Format types ``'x'`` and ``'X'`` show a hex-encoded string representation of
WKB or Well-Known Binary, with the case of the output matched the
case of the format type character.

.. _canonical-form:

Canonical form
--------------
When operations are applied on geometries the result is returned according to some
conventions.

In most cases, geometries will be returned in "mild" canonical form:

- the coordinates of exterior rings follow a clockwise orientation and interior
rings have a counter-clockwise orientation. This is the opposite of the OGC
specifications because the choice was made before this was included in the standard.
- the starting point of rings can be changed, but it is undefined
- the order of geometry types in a collection can be changed, but the order is
undefined

When :func:`~shapely.normalize` is used, the "strict" canonical form is applied:

- the coordinates of exterior rings follow a clockwise orientation and interior
rings have a counter-clockwise orientation
- the starting point of rings is lower left
- elements in collections are ordered by geometry type

It is important to note that input geometries do not have to follow these conventions.
17 changes: 9 additions & 8 deletions shapely/_geometry.py
Expand Up @@ -731,14 +731,15 @@ def set_precision(geometry, grid_size, mode="valid_output", **kwargs):
collapse to empty geometries if all vertices are closer together than
grid_size. Z values, if present, will not be modified.
Note: subsequent operations will always be performed in the precision of
the geometry with higher precision (smaller "grid_size"). That same
precision will be attached to the operation outputs.
Also note: input geometries should be geometrically valid; unexpected
results may occur if input geometries are not.
Returns None if geometry is None.
Notes:
* subsequent operations will always be performed in the precision of
the geometry with higher precision (smaller "grid_size"). That same
precision will be attached to the operation outputs.
* input geometries should be geometrically valid; unexpected results may
occur if input geometries are not.
* the geometry returned will be in :ref:`canonical form <canonical-form>`.
* returns None if geometry is None.
Parameters
----------
Expand Down
6 changes: 3 additions & 3 deletions shapely/constructive.py
Expand Up @@ -594,9 +594,9 @@ def make_valid(geometry, method="linework", keep_collapsed=True, **kwargs):
def normalize(geometry, **kwargs):
"""Converts Geometry to normal form (or canonical form).
This method orders the coordinates, rings of a polygon and parts of
multi geometries consistently. Typically useful for testing purposes
(for example in combination with ``equals_exact``).
In :ref:`canonical form <canonical-form>`, the coordinates, rings of a polygon and
parts of multi geometries are ordered consistently. Typically useful for testing
purposes (for example in combination with ``equals_exact``).
Parameters
----------
Expand Down

0 comments on commit 0ded2b4

Please sign in to comment.