-
Notifications
You must be signed in to change notification settings - Fork 156
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
Implement and Test All non-multi-Feature Spatial Predicate Combinations #1064
Changes from 152 commits
96b28a3
b8785f7
c6e3910
45c128c
0f0a0d4
d1fb60c
da247f8
2b7d7fa
dd01d6c
b4ac329
3dc6195
9931ed1
dbd1bbf
bd03668
313c020
1c1e7ce
28d5c13
6abb44e
c400646
d2ac985
23f4363
63eea9d
29050fc
30c9c86
2d64f3b
f99810f
7f606f9
c8ae2dd
ec24574
b1f6207
0050be0
c178414
719d065
05090bb
ca1218d
76c8aac
5c78146
e3aeac7
e0bba71
3d28ee9
32050f9
2420dfe
ac9b755
d904762
102915b
72d6e97
a806371
fbcd2bd
f7c2c98
89a54c5
37cba19
e63c594
66498cf
ce1df18
07401fe
86ad906
1a0072c
b2ea930
dfcd583
1766437
1ff4589
367a420
fbc1618
873525a
0d84603
e4132b0
8dfca13
a3d8b8a
008631e
550fa9b
f45acda
7198f40
eaee84c
9614dff
fc1ca25
b651aaf
8e83ec1
6a931bb
ae39c88
a48dbbf
c0dd549
753334c
a5ec83a
1a2456a
a394ea6
410fd07
bd5aebf
1c98d6d
57517cd
3fc9d44
32c9e0a
713a27a
d0138c9
e60af29
85676d1
f64b461
ddda72c
1c0a018
0d7ca82
12fa90f
b45a731
d753bf0
fe978a3
3b68ec2
aae2f28
5924fd0
96e442e
37daece
7b52117
d7fffac
675f145
2015405
0698322
4fd668e
3de22b3
195028d
6433096
32a18de
9e65cb4
8a1d234
c433949
24e4d9a
a86fb2b
e9dd49e
c813ba7
c3d03cb
5814380
a2bf9d3
92c918c
86dd5b3
4f6f8a8
c14b4ca
6e8f6ee
72ad8c9
6c6f097
c875787
43c50ab
d628a44
2eb4b32
81d85f5
14ec9d7
9855137
ffa7141
35d6bec
f9b2df6
961d199
ebc33b8
30eded7
ded3d74
55bac02
ba4e5c6
805d5f3
9f27a62
69691d8
227bd88
a999014
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,27 @@ | ||
# Copyright (c) 2023, NVIDIA CORPORATION. | ||
|
||
from cuspatial.core.binpreds.binpred_interface import NotImplementedPredicate | ||
from cuspatial.core.binpreds.basic_predicates import ( | ||
_basic_contains_any, | ||
_basic_contains_count, | ||
_basic_equals_count, | ||
_basic_intersects_pli, | ||
) | ||
from cuspatial.core.binpreds.binpred_interface import ( | ||
BinPred, | ||
ImpossiblePredicate, | ||
NotImplementedPredicate, | ||
) | ||
from cuspatial.core.binpreds.feature_equals import EqualsPredicateBase | ||
from cuspatial.core.binpreds.feature_intersects import ( | ||
LineStringPointIntersects, | ||
PointLineStringIntersects, | ||
) | ||
from cuspatial.utils.binpred_utils import ( | ||
LineString, | ||
MultiPoint, | ||
Point, | ||
Polygon, | ||
_points_and_lines_to_multipoints, | ||
_zero_series, | ||
) | ||
|
||
|
||
|
@@ -36,21 +47,65 @@ class CoversPredicateBase(EqualsPredicateBase): | |
pass | ||
|
||
|
||
class LineStringLineStringCovers(BinPred): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't comment on non-changed lines, but please don't add documentation that will go stale quickly, e.g. "in this initial release". Also, the fact that it is implemented using only the equals predicate is an implementation detail, not a feature of the API. Public documentation should cover features and usage of the API, not implementation details. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the clarification, those docs and others definitely needed a cleanup. |
||
def _preprocess(self, lhs, rhs): | ||
# A linestring A covers another linestring B iff | ||
# no point in B is outside of A. | ||
pli = _basic_intersects_pli(lhs, rhs) | ||
points = _points_and_lines_to_multipoints(pli[1], pli[0]) | ||
# Every point in B must be in the intersection | ||
equals = _basic_equals_count(rhs, points) == rhs.sizes | ||
return equals | ||
|
||
|
||
class PolygonPointCovers(BinPred): | ||
def _preprocess(self, lhs, rhs): | ||
return _basic_contains_any(lhs, rhs) | ||
isVoid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
class PolygonLineStringCovers(BinPred): | ||
def _preprocess(self, lhs, rhs): | ||
isVoid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# A polygon covers a linestring if all of the points in the linestring | ||
# are in the interior or exterior of the polygon. This differs from | ||
# a polygon that contains a linestring in that some point of the | ||
# linestring must be in the interior of the polygon. | ||
# Count the number of points from rhs in the interior of lhs | ||
contains_count = _basic_contains_count(lhs, rhs) | ||
# Now count the number of points from rhs in the boundary of lhs | ||
pli = _basic_intersects_pli(lhs, rhs) | ||
intersections = pli[1] | ||
# There may be no intersection, so start with _zero_series | ||
equality = _zero_series(len(rhs)) | ||
if len(intersections) > 0: | ||
matching_length_multipoints = _points_and_lines_to_multipoints( | ||
intersections, pli[0] | ||
) | ||
equality = _basic_equals_count(matching_length_multipoints, rhs) | ||
covers = contains_count + equality >= rhs.sizes | ||
return covers | ||
|
||
|
||
class PolygonPolygonCovers(BinPred): | ||
def _preprocess(self, lhs, rhs): | ||
contains = lhs.contains(rhs) | ||
return contains | ||
|
||
|
||
DispatchDict = { | ||
(Point, Point): CoversPredicateBase, | ||
(Point, MultiPoint): NotImplementedPredicate, | ||
(Point, LineString): PointLineStringIntersects, | ||
(Point, Polygon): CoversPredicateBase, | ||
(Point, LineString): ImpossiblePredicate, | ||
(Point, Polygon): ImpossiblePredicate, | ||
(MultiPoint, Point): NotImplementedPredicate, | ||
(MultiPoint, MultiPoint): NotImplementedPredicate, | ||
(MultiPoint, LineString): NotImplementedPredicate, | ||
(MultiPoint, Polygon): NotImplementedPredicate, | ||
(LineString, Point): LineStringPointIntersects, | ||
(LineString, MultiPoint): NotImplementedPredicate, | ||
(LineString, LineString): NotImplementedPredicate, | ||
(LineString, LineString): LineStringLineStringCovers, | ||
(LineString, Polygon): CoversPredicateBase, | ||
(Polygon, Point): CoversPredicateBase, | ||
(Polygon, Point): PolygonPointCovers, | ||
(Polygon, MultiPoint): CoversPredicateBase, | ||
(Polygon, LineString): CoversPredicateBase, | ||
(Polygon, Polygon): CoversPredicateBase, | ||
(Polygon, LineString): PolygonLineStringCovers, | ||
(Polygon, Polygon): PolygonPolygonCovers, | ||
} |
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.
Is this comment correct? This is contains, not covers. The code for the two looks the same. Is that correct?
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 that in the context of LineString+LineString, .contains and .covers are equivalent. This comment persisting in
feature_contains.py
is not correct, thanks!https://postgis.net/docs/ST_Covers.html
https://postgis.net/docs/ST_Contains.html
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.