-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1158 from rapidsai/branch-23.06
Forward-merge branch-23.06 to branch-23.08
- Loading branch information
Showing
22 changed files
with
970 additions
and
237 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
83 changes: 64 additions & 19 deletions
83
python/cuspatial/cuspatial/core/binpreds/feature_covers.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,101 @@ | ||
# 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, | ||
) | ||
|
||
|
||
class CoversPredicateBase(EqualsPredicateBase): | ||
"""Implements the covers predicate across different combinations of | ||
geometry types. For example, a Point-Polygon covers predicate is | ||
defined in terms of a Point-Point equals predicate. The initial release | ||
implements covers predicates that depend only on the equals predicate, or | ||
depend on no predicate, such as impossible cases like | ||
`LineString.covers(Polygon)`. | ||
For this initial release, cover is supported for the following types: | ||
defined in terms of a Point-Polygon equals predicate. | ||
Point.covers(Point) | ||
Point.covers(Polygon) | ||
LineString.covers(Polygon) | ||
Polygon.covers(Point) | ||
Polygon.covers(MultiPoint) | ||
Polygon.covers(LineString) | ||
Polygon.covers(Polygon) | ||
""" | ||
|
||
pass | ||
|
||
|
||
class LineStringLineStringCovers(BinPred): | ||
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) | ||
|
||
|
||
class PolygonLineStringCovers(BinPred): | ||
def _preprocess(self, lhs, rhs): | ||
# 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, | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.