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

Prepared contains differs from normal contains #519

Closed
mrocklin opened this issue Sep 6, 2017 · 12 comments
Closed

Prepared contains differs from normal contains #519

mrocklin opened this issue Sep 6, 2017 · 12 comments

Comments

@mrocklin
Copy link

mrocklin commented Sep 6, 2017

This fails. I don't think it should. I could be mistaken though.

from shapely.geometry import Point, Polygon
import shapely.prepared

point = Point(0.95, 0.05)
geom = Polygon([(0, 0), (1, 0), (0, 1), (0, 0)])

assert shapely.prepared.prep(geom).contains(point) == geom.contains(point)
>>> shapely.__version__
'1.6b4'

I'm on linux. I've installed Shapely from conda-forge.

@ocefpaf
Copy link
Contributor

ocefpaf commented Sep 6, 2017

I'm on linux. I've installed Shapely from conda-forge

We (conda-forge) never packaged '1.6b4' 😕

@mrocklin
Copy link
Author

mrocklin commented Sep 6, 2017 via email

@mrocklin
Copy link
Author

mrocklin commented Sep 6, 2017

Sorry, 1.5.17post1

In [1]: import shapely

In [2]: shapely.__version__
Out[2]: '1.5.17.post1'

In [3]: from shapely.geometry import Point, Polygon
   ...: import shapely.prepared
   ...: 
   ...: point = Point(0.95, 0.05)
   ...: geom = Polygon([(0, 0), (1, 0), (0, 1), (0, 0)])
   ...: 
   ...: assert shapely.prepared.prep(geom).contains(point) == geom.contains(point)
   ...: 
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-3-91a2da531b6f> in <module>()
      5 geom = Polygon([(0, 0), (1, 0), (0, 1), (0, 0)])
      6 
----> 7 assert shapely.prepared.prep(geom).contains(point) == geom.contains(point)

AssertionError: 

@snorfalorpagus
Copy link
Member

snorfalorpagus commented Sep 6, 2017

I can reproduce this. Perhaps this is a bug in GEOS?

(I didn't mean to close this...)

@mrocklin
Copy link
Author

mrocklin commented Sep 6, 2017

Yes, I'm seeing the same thing when I bypass Shapely and go straight to the GEOS C-api in Cython.

@ocefpaf
Copy link
Contributor

ocefpaf commented Sep 6, 2017

FYI I just add #519 (comment) as a test to the shapely feedstock and built with geos 3.6.0, 3.6.1, and 3.6.2 and they all fail 😒

@sgillies
Copy link
Contributor

sgillies commented Sep 6, 2017

I distribute GEOS 3.4.2 with the shapely wheels that I put on PyPI and can't reproduce the issue with that older version.

>>> shapely.geos.geos_version
(3, 4, 2)
>>> shapely.prepared.prep(geom).contains(point)
True

@mrocklin
Copy link
Author

mrocklin commented Sep 6, 2017

My error was on 3.5.1

(geopandas) mrocklin@carbon:~$ conda list | grep geos
geos                      3.5.1                         1    conda-forge

@sgillies
Copy link
Contributor

sgillies commented Sep 6, 2017

I've created a ticket upstream: https://trac.osgeo.org/geos/ticket/841. @mrocklin @snorfalorpagus can you confirm that I reported correctly?

@ocefpaf
Copy link
Contributor

ocefpaf commented Sep 6, 2017

geos 3.4.2 works for the conda package too. But we cannot afford to downgrade to that version 😒

@mrocklin
Copy link
Author

mrocklin commented Sep 6, 2017

Looks good to me. Thanks for going through the effort of raising upstream @sgillies

@sgillies
Copy link
Contributor

sgillies commented Sep 6, 2017

This seems to be a wontfix and I've closed the upstream issue. Strictly speaking, the point is on the boundary of the polygon and thus is not contained. Due to numerical precision issues, it may be computed to not be on the boundary, and that's what I see in my test. Something has changed since 3.4.2, but the results are actually more correct for one of the polygons. I didn't note above whether it was prep(geom).contains(point) or geom.contains(point) that was False with GEOS 3.5.1.

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

No branches or pull requests

4 participants