Open theroggy opened 5 months ago
Is there an intention to return geometries in canonical form, or should the user use
normalize
if he wants a geometry to have a predictable form?
Geometries are returned in "mild" canonical form. In particular, polygon outputs have a consistent orientation for their rings (CW for shells, CCW for holes - which is opposite to more recent convention, but that's another issue). Some other functions preserve line orientation (which can result in "non-normalized" output. Otherwise, further normalization is avoided in order to maximise performance.
If strict normalization is required it needs to be performed explicitly by the caller.
The setPrecision
operation is actually using the overlay code under the hood, which is why the output always has canonical orientation (which may be different to the input). I can see some justification for preserving the orientation of the input (although I'm curious why that is important?).
Although, given the fact that precision reduction can change the topology of a geometry dramatically, I'm not sure how technically feasible this is, or what performance would look like.
I submitted the original report in the shapely repo that led to this issue report.
My requirement is not that orientation be preserved but that the form in which polygons are returned from various operations be consistent, predictable, and documented. No surprises! @theroggy's further investigations led to uncovering the various confusing seeming inconsistencies in behaviour they have reported in this issue. If normalize
is required after setPrecision
to guarantee known formatting of polygon vertices, then that's OK for my application, so long as it is well documented.
I certainly don't suggest that performance to be compromised in pursuit of the needs of an obscure requirement.
FWIW the application is one where I need to examine polygon symmetries, algorithms for which misbehave if the orientation and start vertex of a polygon's coordinate sequence changes unexpectedly after a step like setting precision which might naively be expected to have no side effects actually changes the start vertex and/or orientation of a polygon.
I (tried to) document the "mild" versus "strict" canonical forms and when they are applied in this shapely PR: https://github.com/shapely/shapely/pull/1964/files
I wouldn't count on "mild" canonical form having any particular permanence, as changes in the practical implementations of overlay code can and will change it over time. It's a "current state" thing, not a matter of any formal definition we do or will follow. The output of normalize should remain stable over time, modulo changes or additions that might be forced on us by things we forgot to normalize initially, or discovered had other effects (the normalized form of a closed linestring it the one that haunts my dreams).
I wouldn't count on "mild" canonical form having any particular permanence, as changes in the practical implementations of overlay code can and will change it over time. It's a "current state" thing, not a matter of any formal definition we do or will follow. The output of normalize should remain stable over time, modulo changes or additions that might be forced on us by things we forgot to normalize initially, or discovered had other effects (the normalized form of a closed linestring it the one that haunts my dreams).
OK, thanks, I'll make it explicit in the documentation that the "Mild" canonical form is just the current state of affairs but that it is not to be counted on and is likely to change in the future.
It was noticed in PR https://github.com/shapely/shapely/pull/1964 that (some?) functions most of the time don't seem to return results in "canonical form", at least for some aspects of it.
Is there an intention to return geometries in canonical form, or should the user use
normalize
if he wants a geometry to have a predictable form?Output: