-
Notifications
You must be signed in to change notification settings - Fork 157
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
Add contains
predicate.
#1086
Add contains
predicate.
#1086
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attention span cutting off. Part 1 review. Will continue after some rest.
python/cuspatial/cuspatial/core/binpreds/complex_geometry_predicate.py
Outdated
Show resolved
Hide resolved
python/cuspatial/cuspatial/core/binpreds/complex_geometry_predicate.py
Outdated
Show resolved
Hide resolved
python/cuspatial/cuspatial/core/binpreds/complex_geometry_predicate.py
Outdated
Show resolved
Hide resolved
def _convert_quadtree_result_from_part_to_polygon_indices( | ||
self, lhs, point_result | ||
): | ||
"""Convert the result of a quadtree contains_properly call from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it matter if this internal function is used for contains_properly
? It seems like it can be applied generically to all other predicates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is only used in contains_properly
. I will move it to binpred_utils.py
if another predicate depends on it.
python/cuspatial/cuspatial/core/binpreds/feature_contains_properly.py
Outdated
Show resolved
Hide resolved
Perhaps use a more descriptive name for this PR. After about 6 of these PRs, my eyes have started glazing over whenever I see "refactor" and "contains" in a PR title. And if anyone reads our changelog, they are going to wonder why the heck we refactor contains so frequently. |
contains
and contains_properly
.contains
function.
python/cuspatial/cuspatial/core/binpreds/contains_geometry_processor.py
Outdated
Show resolved
Hide resolved
python/cuspatial/cuspatial/core/binpreds/contains_geometry_processor.py
Outdated
Show resolved
Hide resolved
python/cuspatial/cuspatial/core/binpreds/feature_contains_properly.py
Outdated
Show resolved
Hide resolved
python/cuspatial/cuspatial/core/binpreds/feature_contains_properly.py
Outdated
Show resolved
Hide resolved
result = pairwise_multipoint_equals_count(lhs, rhs) | ||
return result | ||
|
||
def _basic_intersects_pli(self, other): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pli
? Please avoid unnecessary abbreviation.
It also seems to me that the other intersection should be called _basic_point_intersects
since that computes point intersections while this is _basic_intersects
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pli: pairwise_linestring_intersection. This returns the unmodified results of the pairwise_linestring_intersection
call, hence pli
. I'll think about some renamings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be nice to separate this file into test_[name_of_binpreds]
for each tested binpreds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file only covers an extremely small range of within, overlaps, and intersects tests. I'm happy to write more tests in specific files once test dispatching with passing tests is merged in #1064.
return result | ||
|
||
|
||
def _linestrings_is_degenerate(geoseries): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove this now that #1093 is merged?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably, I'd like to leave that for a future issue/PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created an issue to track this #1113
…erly.py Co-authored-by: Michael Wang <isVoid@users.noreply.github.com>
Co-authored-by: Michael Wang <isVoid@users.noreply.github.com>
…l into feature/_basic_binpreds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly docs, a few structural questions.
python/cuspatial/cuspatial/core/binpreds/contains_geometry_processor.py
Outdated
Show resolved
Hide resolved
python/cuspatial/cuspatial/core/binpreds/contains_geometry_processor.py
Outdated
Show resolved
Hide resolved
python/cuspatial/cuspatial/core/binpreds/feature_contains_properly.py
Outdated
Show resolved
Hide resolved
python/cuspatial/cuspatial/core/binpreds/feature_contains_properly.py
Outdated
Show resolved
Hide resolved
The size of a multipoint is the number of points in its single point. | ||
The size of a point is 1. | ||
""" | ||
if contains_only_polygons(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't this be a lot simpler? Any geometry, regardless of complexity, stores a flat array of coordinates. The number of points is just the length of the xy points array, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason for this logic is because sizes
returns the size of each row of the GeoSeries
. For example
x = cuspatial.GeoSeries([
LineString([(0, 0), (1, 1)]),
LineString([(0, 0), (1, 1), (2, 2)]),
LineString([(0, 0), (1, 1), (2, 2), (3, 3)]),
])
print(x.sizes)
0 2
1 3
2 4
dtype: int32
The .xy array in this case contains all of the points for all of the features in the GeoSeries:
x.lines.xy
0 0.0
1 0.0
2 1.0
3 1.0
4 0.0
5 0.0
6 1.0
7 1.0
8 2.0
9 2.0
10 0.0
11 0.0
12 1.0
13 1.0
14 2.0
15 2.0
16 3.0
17 3.0
dtype: float64
But has no information about the lengths of the individual geometries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sum(x.sizes) == 9
and len(x.lines.xy) / 2 == 9
. So why doesn't the latter serve the purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, the sizes are used for each row of the GeoSeries
to determine if the .contains
(boundary inclusive) predicate has been met:
return contains + intersects >= rhs.sizes
Where contains is a cudf.Series
of the number of points that satisfied .contains_properly
for each row in the GeoSeries, and intersects is a cudf.Series
of the number of points that satisfied .intersects
for those same rows in the GeoSeries. So if I had a GeoSeries of a length-three polygon and a length 4 polygon, sizes would be
0 3
1 4
dtype: int32
and in the cast of a self-contains test contains would be
0 0
1 0
dtype: int32
and intersects would be
0 3
0 4
dtype: int32
so the predicate result of .contains
is
`contains_properly + intersects >= rhs.sizes ==
0 True
1 True
dtype: bool
Does that properly answer your question? I'm not using the sum of the sizes in the GeoSeries
, but each individually.
Co-authored-by: Mark Harris <783069+harrism@users.noreply.github.com>
Co-authored-by: Mark Harris <783069+harrism@users.noreply.github.com>
Co-authored-by: Mark Harris <783069+harrism@users.noreply.github.com>
…l into feature/_basic_binpreds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just two small comments relating to documentation above.
Also please address my two remaining open comments. |
Co-authored-by: Mark Harris <783069+harrism@users.noreply.github.com>
…l into feature/_basic_binpreds
/merge |
Closes #1077
Depends on #1022
This PR is a precursor to #1064.
Description
This PR creates a new
.contains
predicate that uses the sum of the result of the.contains_properly
predicate and the.intersects
predicate to compute the.contains
relationship, boundary inclusive.Checklist