Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Equivalent polygons are not equal with geos 3.13 #1177

Closed
mroeschke opened this issue Oct 5, 2024 · 5 comments
Closed

Equivalent polygons are not equal with geos 3.13 #1177

mroeschke opened this issue Oct 5, 2024 · 5 comments

Comments

@mroeschke
Copy link

(shapely_test) :~$ conda list | grep shapely
shapely                   2.0.6           py312h391bc85_2    conda-forge
(shapely_test) :~$ conda list | grep geos
geos                      3.13.0               h5888daf_0    conda-forge
(shapely_test) :~$ python
Python 3.12.7 | packaged by conda-forge | (main, Oct  4 2024, 16:05:46) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import shapely; from shapely.geometry import Polygon
>>> g11 = Polygon(
...     ((97, 98), (99, 101), (102, 103), (101, 108)),
...     [((106, 107), (108, 109), (110, 111), (113, 108))],
... )
>>> shapely.equals(g11, g11)
np.False_
(shapely_test3) :~$ conda list | grep shapely
shapely                   2.0.6           py312h6cab151_1    conda-forge
(shapely_test3) :~$ conda list | grep geos
geos                      3.12.2               he02047a_1    conda-forge
(shapely_test3) :~$ python
Python 3.12.7 | packaged by conda-forge | (main, Oct  4 2024, 16:05:46) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import shapely; from shapely.geometry import Polygon
>>> 
>>> g11 = Polygon(
...     ((97, 98), (99, 101), (102, 103), (101, 108)),
...     [((106, 107), (108, 109), (110, 111), (113, 108))],
... )
>>> shapely.equals(g11, g11)
np.True_

Not sure if this is related to #1170, but I would expected this to be True with geos 3.13

@dr-jts
Copy link
Contributor

dr-jts commented Oct 5, 2024

Is the geometry the same as the following WKT?

POLYGON ((97 98, 99 101, 102 103, 101 108, 97 98), (106 107, 108 109, 110 111, 113 108, 106 107))
image

If so, this is an invalid polygon, since the hole lies outside the shell. Invalid geometries are undefined for the results of spatial predicates, and so there is no guarantee that the results are consistent between different Relate algorithms.

@mroeschke
Copy link
Author

Is the geometry the same as the following WKT?

Well according to shapely.equals, this also depends on what version of geos is installed

In [1]: import shapely; from shapely.geometry import Polygon

In [2]: >>> g11 = Polygon(
   ...: ...     ((97, 98), (99, 101), (102, 103), (101, 108)),
   ...: ...     [((106, 107), (108, 109), (110, 111), (113, 108))],
   ...: ... )

In [3]: g12 = shapely.from_wkt("POLYGON ((97 98, 99 101, 102 103, 101 108, 97 98), (106 107, 108 109, 110 111, 113 108, 106 107))")

In [4]: g11.equals(g12)
Out[4]: True
$ conda list geos
#
# Name                    Version                   Build  Channel
geos                      3.12.2               he02047a_1    conda-forge
$ conda install -c conda-forge geos=3.13
...
$ conda list geos
#
# Name                    Version                   Build  Channel
geos                      3.13.0               h5888daf_0    conda-forge
In [1]: import shapely; from shapely.geometry import Polygon

In [2]: >>> g11 = Polygon(
   ...: ...     ((97, 98), (99, 101), (102, 103), (101, 108)),
   ...: ...     [((106, 107), (108, 109), (110, 111), (113, 108))],
   ...: ... )

In [3]: g12 = shapely.from_wkt("POLYGON ((97 98, 99 101, 102 103, 101 108, 97 98), (106 107, 108 109, 110 111, 113 108, 106 107))")

In [4]: g11.equals(g12)
Out[4]: False

Sorry I am not really well versed in geospatial concepts, but you're saying an invalid polygon (or any geometry) is never equal to itself because it is invalid?

@dr-jts
Copy link
Contributor

dr-jts commented Oct 7, 2024

Well according to shapely.equals, this also depends on what version of geos is installed

Sorry I am not really well versed in geospatial concepts, but you're saying an invalid polygon (or any geometry) is never equal to itself because it is invalid?

Invalid geometries are simply not handled by the topological predicates. So they may return any result for an invalid geometry. And this may vary according to the version of GEOS used.

@pramsey
Copy link
Member

pramsey commented Oct 7, 2024

I wonder if our equals() does a quick equalsexact(), particularly for features like polygons that might be invalid in ways that defeat equals().

@dr-jts
Copy link
Contributor

dr-jts commented Oct 7, 2024

I wonder if our equals() does a quick equalsexact(), particularly for features like polygons that might be invalid in ways that defeat equals().

If this is the desired behaviour it's easy for API users to call GEOSEqualsIdentical or GEOSEqualsExact before calling GEOSEquals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants