Refactor shapely.prepared to use prepared base geometries#1039
Merged
jorisvandenbossche merged 1 commit intoshapely:shapely-2.0from Dec 16, 2020
Merged
Conversation
| from pygeos import STRtree | ||
| tree = STRtree([other]) | ||
| idx = tree.query(self.context, predicate="contains_properly") | ||
| return bool(len(idx)) |
Member
Author
There was a problem hiding this comment.
I opened pygeos/pygeos#267 to add this to pygeos properly
mwtoews
approved these changes
Dec 9, 2020
Member
mwtoews
left a comment
There was a problem hiding this comment.
Changes look good, and I appreciate _geom and __geom__ have been cleaned up too, hopefully no downstream issues may rise from this.
I did a quick "timeit" comparison using:
from shapely.geometry import Point, Polygon
from shapely.prepared import prep
triangle = Polygon(((0.0, 0.0), (1.0, 1.0), (1.0, -1.0)))
pt = Point(0.5, 0.5)
%timeit prep(triangle).intersects(pt)and I see a minor slowdown from ~ 5 µs to 9 µs, which is acceptable. The first of these loops takes several times longer, which confirms that PyGEOS does some in-place caching of the prepared geometry.
This is also the last use of delegated, so it could be considered to be cleaned up soon. And I suppose the whole impl module could be cleaned up too.
sgillies
approved these changes
Dec 11, 2020
Contributor
|
Yes, we're all in on GEOS now, so impl.py can be deleted. |
Member
Author
|
OK, next PR to remove |
jorisvandenbossche
added a commit
to jorisvandenbossche/shapely
that referenced
this pull request
Apr 5, 2021
jorisvandenbossche
added a commit
to jorisvandenbossche/shapely
that referenced
this pull request
Apr 5, 2021
jorisvandenbossche
added a commit
to jorisvandenbossche/shapely
that referenced
this pull request
May 27, 2021
jorisvandenbossche
added a commit
to jorisvandenbossche/shapely
that referenced
this pull request
May 27, 2021
jorisvandenbossche
added a commit
to jorisvandenbossche/shapely
that referenced
this pull request
Aug 20, 2021
jorisvandenbossche
added a commit
that referenced
this pull request
Aug 21, 2021
jorisvandenbossche
added a commit
to jorisvandenbossche/shapely
that referenced
this pull request
Sep 30, 2021
jorisvandenbossche
added a commit
that referenced
this pull request
Oct 27, 2021
jorisvandenbossche
added a commit
that referenced
this pull request
Oct 28, 2021
jorisvandenbossche
added a commit
that referenced
this pull request
Nov 8, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In PyGEOS, the GEOSPreparedGeometry is now stored on the same python extension type (C struct) as used for the base Geometry class (and there are functions to (un)prepare a geometry object "in place"). If an object is prepared, the predicate functions will automatically use it.
So in the future, we can make this interface in Shapely easier, but on the short term, I refactored the existing shapely PreparedGeometry to use the prepared functionality of PyGEOS.
(since there is not yet an alternative for this in Shapely 1.8, so we can't deprecate this yet (if we would want that long term), and keep a working version initially in Shapely 2.0)