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

Create GeoSeries.contains_properly method using point_in_polygon. #749

Merged
merged 104 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from 102 commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
758c66b
Add tests to verify border-exclusion and modify point_in_polygon.cuh …
thomcom Oct 17, 2022
731987b
Merge branch 'feature/pip_boundary_exclusion_test' into feature/GeoSe…
thomcom Oct 19, 2022
76c8b1d
Trying to write contains tests, having difficulties.
thomcom Oct 19, 2022
beacf76
Pass all clockwise polygon tests.
thomcom Oct 20, 2022
67d6153
Test of boundary exclusion.
thomcom Oct 21, 2022
8a19829
Create is_point_colinear_with_polygon method. Get colinearity working.
thomcom Oct 21, 2022
d2f93ed
Merge branch 'feature/GeoSeries.contains' into test-contains
thomcom Oct 21, 2022
7cce26b
Tweak one test because it shares a point with the offending polygon.
thomcom Oct 21, 2022
11be135
Modify colinearity test to early terminate.
thomcom Oct 21, 2022
5aa9c09
Create a point_in_polygon_one_to_one for better correspondence with c…
thomcom Oct 21, 2022
a9c1806
Wresling with pre-commit.
thomcom Oct 21, 2022
1b4f850
Rename to pairwise.
thomcom Oct 21, 2022
cba43a4
Need to include the proper file.
thomcom Oct 21, 2022
fbfd0b7
Move shared is_point_in_polygon to its own file.
thomcom Oct 24, 2022
a0cfbe2
Remove unneeded includes.
thomcom Oct 24, 2022
046e4a1
Fix the tests that should no longer pass.
thomcom Oct 24, 2022
c87e741
Fix the tests that should no longer pass.
thomcom Oct 24, 2022
7f1b632
Now we allow open or closed polygons again.
thomcom Oct 24, 2022
cd205b2
Write tests for pairwise point in polygon.
thomcom Oct 24, 2022
121e146
Create new branch with pairwise_point_in_polygon cpp changes.
thomcom Oct 24, 2022
756282d
Clean up docs on cursory review.
thomcom Oct 24, 2022
f5f7777
Use T as TypeParam
thomcom Oct 24, 2022
ebb266e
Merge
thomcom Oct 24, 2022
e784307
Writing tests and implementation for polygon/point contains.
thomcom Oct 24, 2022
2eb4b9d
Merge branch 'branch-22.12' into feature/GeoSeries.contains
thomcom Oct 24, 2022
f53acec
Create polygon and multipolygon generator.
thomcom Oct 24, 2022
390890d
Refactor and create exhaustive polygon contains tests.
thomcom Oct 25, 2022
a6f8f69
Add epsilon to colinearity test.
thomcom Oct 25, 2022
87020fa
Formatting.
thomcom Oct 25, 2022
08e845b
Merge branch 'feature/pairwise_point_in_polygon' into feature/GeoSeri…
thomcom Oct 25, 2022
9b2a69b
Boundary cases that are inconsistent.
thomcom Oct 25, 2022
3a34016
Add EPSILON and refactor some tests.
thomcom Oct 25, 2022
e8af434
Remove stale comment.
thomcom Oct 25, 2022
70437da
Correct comments
thomcom Oct 25, 2022
1028860
Merge branch 'feature/pairwise_point_in_polygon' into feature/GeoSeri…
thomcom Oct 25, 2022
832167f
Add polygon.contains(linestring)
thomcom Oct 26, 2022
cc87c86
Test points in polygons.
thomcom Oct 26, 2022
1fdd921
Revert "Merge branch 'feature/pairwise_point_in_polygon' into feature…
thomcom Oct 27, 2022
8e8bc81
Fixed
thomcom Oct 27, 2022
0efb650
Add the polygon with a hole with a linestring crossing it case.
thomcom Oct 27, 2022
a092a6e
Add polygons and multilinestrings and some known failure cases.
thomcom Oct 28, 2022
c55ac72
Rename is_point_in_polygon.cuh
thomcom Nov 1, 2022
5624068
Keep only colinearity epsilon.
thomcom Nov 1, 2022
9bb615b
Revert "Merge branch 'feature/pairwise_point_in_polygon' into feature…
thomcom Nov 2, 2022
d27672d
Merge branch 'branch-22.12' into feature/GeoSeries.contains
thomcom Nov 2, 2022
7550399
Change to grid/stride loop.
thomcom Nov 4, 2022
8786614
Merge branch 'branch-22.12' into feature/pairwise_point_in_polygon
thomcom Nov 28, 2022
be5a5c0
Fix bug with grid-stride loop and switch to for comparison.
thomcom Nov 28, 2022
f7bbf10
Update cpp/include/cuspatial/pairwise_point_in_polygon.hpp
thomcom Nov 28, 2022
b6d55b8
Update cpp/include/cuspatial/experimental/pairwise_point_in_polygon.cuh
thomcom Nov 28, 2022
d3d7533
Update cpp/include/cuspatial/experimental/pairwise_point_in_polygon.cuh
thomcom Nov 28, 2022
0edd2df
run-clang-format.py
thomcom Nov 28, 2022
1c02f3c
Improve grid stride loop computations.
thomcom Nov 29, 2022
89169ee
Update cpp/include/cuspatial/experimental/detail/is_point_in_polygon.cuh
thomcom Nov 29, 2022
e5e937f
Merge branch 'feature/pairwise_point_in_polygon' of github.com:thomco…
thomcom Nov 29, 2022
332d5c0
Merge
thomcom Nov 29, 2022
0cf4602
Resolve circular import issue.
thomcom Nov 29, 2022
66000c3
Pass pytests and refactor to got/expected pattern.
thomcom Nov 29, 2022
88312c9
Add one more test case.
thomcom Nov 29, 2022
2c893d3
Write detailed xfail descriptions.
thomcom Nov 29, 2022
f81ac93
Update python/cuspatial/cuspatial/_lib/cpp/pairwise_point_in_polygon.pxd
thomcom Nov 29, 2022
104657f
Update python/cuspatial/cuspatial/_lib/pairwise_point_in_polygon.pyx
thomcom Nov 29, 2022
4bd3f49
Update python/cuspatial/cuspatial/core/geoseries.py
thomcom Nov 29, 2022
0cdb9f3
Update python/cuspatial/cuspatial/core/geoseries.py
thomcom Nov 29, 2022
437eea9
Tweak a comment.
thomcom Nov 29, 2022
ec545ac
Add comments back to generators.
thomcom Nov 29, 2022
4aa4064
Write more fixture docs.
thomcom Nov 29, 2022
8691e5e
Reorder got/expected.
thomcom Nov 29, 2022
1139316
Update one more test description.
thomcom Nov 29, 2022
e62aa9f
Create .contains examples.
thomcom Nov 29, 2022
22b9241
Move .contains docs to geoseries.py
thomcom Nov 29, 2022
597d932
Remove binops with quadtree.
thomcom Nov 29, 2022
70a4991
Fix test issue with sporadic groupby reordering.
thomcom Nov 29, 2022
104912d
Fix benchmark regression from 22.12
thomcom Nov 29, 2022
fee62b9
Fix bug with benchmark point_in_polygon
thomcom Nov 29, 2022
0b1dc79
Poly offsets is n+1 the size of points.
thomcom Nov 29, 2022
166ecb3
Update python/cuspatial/cuspatial/tests/test_contains.py
thomcom Nov 29, 2022
9e8892a
Update python/cuspatial/cuspatial/core/geoseries.py
thomcom Nov 29, 2022
166c5cf
Update python/cuspatial/cuspatial/tests/conftest.py
thomcom Nov 29, 2022
e92686d
Update python/cuspatial/cuspatial/tests/conftest.py
thomcom Nov 29, 2022
88b864d
DRY-ify a function.
thomcom Nov 29, 2022
85b2dab
Merge branch 'feature/GeoSeries.contains' of github.com:thomcom/cuspa…
thomcom Nov 29, 2022
726e637
Merge branch 'branch-22.12' into feature/GeoSeries.contains
thomcom Nov 29, 2022
61c48e2
Handling @isVoid's comments.
thomcom Nov 29, 2022
903e0ae
Rename to contains_properly
thomcom Nov 29, 2022
dea2b96
Update python/cuspatial/cuspatial/core/geoseries.py
thomcom Nov 29, 2022
ad308fb
Update python/cuspatial/cuspatial/core/geoseries.py
thomcom Nov 29, 2022
0854a65
Update python/cuspatial/cuspatial/core/geoseries.py
thomcom Nov 29, 2022
cd6bd66
Handle more review comments.
thomcom Nov 29, 2022
141b86c
Merge branch 'feature/GeoSeries.contains' of github.com:thomcom/cuspa…
thomcom Nov 29, 2022
d72df1c
Comment
thomcom Nov 29, 2022
d08ad01
Fix alignment.
thomcom Nov 29, 2022
cb1b149
Fix example layout again.
thomcom Nov 30, 2022
8db29b6
Update python/cuspatial/cuspatial/core/geoseries.py
thomcom Nov 30, 2022
f31b70e
Update python/cuspatial/cuspatial/core/geoseries.py
thomcom Nov 30, 2022
80f5ea1
Update python/cuspatial/cuspatial/core/geoseries.py
thomcom Nov 30, 2022
4a594b9
Apply suggestions from code review
thomcom Nov 30, 2022
4a651f1
Get rid of GeoPandas round trip in .contains_properly example and fix…
thomcom Nov 30, 2022
d401c58
Merge branch 'feature/GeoSeries.contains' of github.com:thomcom/cuspa…
thomcom Nov 30, 2022
1c4f1bc
Style issue, black is hopefully not breaking flake8 in CI.
thomcom Nov 30, 2022
d007515
Add __init__.py to binops hoping to resolve CI issue.
thomcom Nov 30, 2022
91c09af
Need test_contains_properly.py
thomcom Nov 30, 2022
0d32a64
Remove xfails.
thomcom Nov 30, 2022
70822a8
Update python/cuspatial/cuspatial/core/geoseries.py
thomcom Nov 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions python/cuspatial/benchmarks/api/bench_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,8 @@ def bench_pairwise_linestring_distance(benchmark, gpu_dataframe):
geometry = gpu_dataframe["geometry"]
benchmark(
cuspatial.pairwise_linestring_distance,
geometry.polygons.ring_offset,
geometry.polygons.x,
geometry.polygons.y,
geometry.polygons.ring_offset,
geometry.polygons.x,
geometry.polygons.y,
geometry,
geometry,
)


Expand Down Expand Up @@ -165,8 +161,8 @@ def bench_quadtree_on_points(benchmark, gpu_dataframe):

def bench_quadtree_point_in_polygon(benchmark, polygons):
polygons = polygons["geometry"].polygons
x_points = (cupy.random.random(10000000) - 0.5) * 360
y_points = (cupy.random.random(10000000) - 0.5) * 180
x_points = (cupy.random.random(50000000) - 0.5) * 360
y_points = (cupy.random.random(50000000) - 0.5) * 180
scale = 5
max_depth = 7
min_size = 125
Expand Down Expand Up @@ -263,15 +259,16 @@ def bench_quadtree_point_to_nearest_linestring(benchmark):


def bench_point_in_polygon(benchmark, gpu_dataframe):
x_points = (cupy.random.random(10000000) - 0.5) * 360
y_points = (cupy.random.random(10000000) - 0.5) * 180
x_points = (cupy.random.random(50000000) - 0.5) * 360
y_points = (cupy.random.random(50000000) - 0.5) * 180
short_dataframe = gpu_dataframe.iloc[0:32]
geometry = short_dataframe["geometry"]
polygon_offset = cudf.Series(geometry.polygons.geometry_offset[0:31])
benchmark(
cuspatial.point_in_polygon,
x_points,
y_points,
geometry.polygons.geometry_offset[0:31],
polygon_offset,
geometry.polygons.ring_offset,
geometry.polygons.x,
geometry.polygons.y,
Expand Down
1 change: 1 addition & 0 deletions python/cuspatial/cuspatial/_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ set(cython_sources
interpolate.pyx
nearest_points.pyx
point_in_polygon.pyx
pairwise_point_in_polygon.pyx
polygon_bounding_boxes.pyx
linestring_bounding_boxes.pyx
quadtree.pyx
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (c) 2022, NVIDIA CORPORATION.

from libcpp.memory cimport unique_ptr

from cudf._lib.column cimport column, column_view


cdef extern from "cuspatial/pairwise_point_in_polygon.hpp" \
namespace "cuspatial" nogil:
cdef unique_ptr[column] pairwise_point_in_polygon(
const column_view & test_points_x,
const column_view & test_points_y,
const column_view & poly_offsets,
const column_view & poly_ring_offsets,
const column_view & poly_points_x,
const column_view & poly_points_y
) except +
42 changes: 42 additions & 0 deletions python/cuspatial/cuspatial/_lib/pairwise_point_in_polygon.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright (c) 2022, NVIDIA CORPORATION.

from libcpp.memory cimport unique_ptr
from libcpp.utility cimport move

from cudf._lib.column cimport Column, column, column_view

from cuspatial._lib.cpp.pairwise_point_in_polygon cimport (
pairwise_point_in_polygon as cpp_pairwise_point_in_polygon,
)


def pairwise_point_in_polygon(
Column test_points_x,
Column test_points_y,
Column poly_offsets,
Column poly_ring_offsets,
Column poly_points_x,
Column poly_points_y
):
cdef column_view c_test_points_x = test_points_x.view()
cdef column_view c_test_points_y = test_points_y.view()
cdef column_view c_poly_offsets = poly_offsets.view()
cdef column_view c_poly_ring_offsets = poly_ring_offsets.view()
cdef column_view c_poly_points_x = poly_points_x.view()
cdef column_view c_poly_points_y = poly_points_y.view()

cdef unique_ptr[column] result

with nogil:
result = move(
cpp_pairwise_point_in_polygon(
c_test_points_x,
c_test_points_y,
c_poly_offsets,
c_poly_ring_offsets,
c_poly_points_x,
c_poly_points_y
)
)

return Column.from_unique_ptr(move(result))
Empty file.
89 changes: 89 additions & 0 deletions python/cuspatial/cuspatial/core/binops/contains.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Copyright (c) 2022, NVIDIA CORPORATION.
harrism marked this conversation as resolved.
Show resolved Hide resolved

from cudf import Series
from cudf.core.column import as_column

from cuspatial._lib.pairwise_point_in_polygon import (
pairwise_point_in_polygon as cpp_pairwise_point_in_polygon,
)
from cuspatial._lib.point_in_polygon import (
point_in_polygon as cpp_point_in_polygon,
)
from cuspatial.utils.column_utils import normalize_point_columns


def contains_properly(
test_points_x,
test_points_y,
poly_offsets,
poly_ring_offsets,
poly_points_x,
poly_points_y,
):
"""Compute from a series of points and a series of polygons which points
are properly contained within the corresponding polygon. Polygon A contains
Point B properly if B intersects the interior of A but not the boundary (or
exterior).

Note that polygons must be closed: the first and last vertex of each
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be in a Note section as well?

polygon must be the same.

Parameters
----------
test_points_x
x-coordinate of points to test for containment
test_points_y
y-coordinate of points to test for containment
poly_offsets
beginning index of the first ring in each polygon
poly_ring_offsets
beginning index of the first point in each ring
poly_points_x
x-coordinates of polygon vertices
poly_points_y
y-coordinates of polygon vertices

Returns
-------
result : cudf.Series
A Series of boolean values indicating whether each point falls
within its corresponding polygon.
"""

if len(poly_offsets) == 0:
return Series()
(
test_points_x,
test_points_y,
poly_points_x,
poly_points_y,
) = normalize_point_columns(
as_column(test_points_x),
as_column(test_points_y),
as_column(poly_points_x),
as_column(poly_points_y),
)
poly_offsets_column = as_column(poly_offsets, dtype="int32")
poly_ring_offsets_column = as_column(poly_ring_offsets, dtype="int32")

thomcom marked this conversation as resolved.
Show resolved Hide resolved
if len(test_points_x) == len(poly_offsets):
thomcom marked this conversation as resolved.
Show resolved Hide resolved
pip_result = cpp_pairwise_point_in_polygon(
test_points_x,
test_points_y,
poly_offsets_column,
poly_ring_offsets_column,
poly_points_x,
poly_points_y,
)
else:
pip_result = cpp_point_in_polygon(
thomcom marked this conversation as resolved.
Show resolved Hide resolved
test_points_x,
test_points_y,
poly_offsets_column,
poly_ring_offsets_column,
poly_points_x,
poly_points_y,
)

result = Series(pip_result, dtype="bool")
thomcom marked this conversation as resolved.
Show resolved Hide resolved
return result
Loading