當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python cuspatial.point_in_polygon用法及代碼示例

用法:

cuspatial.point_in_polygon(test_points_x, test_points_y, poly_offsets, poly_ring_offsets, poly_points_x, poly_points_y)

根據一組點和一組多邊形計算哪些點屬於哪些多邊形。請注意,polygons_(x,y) 必須指定為封閉多邊形:每個多邊形的第一個和最後一個坐標必須相同。

參數

test_points_x

測試點的 x 坐標

test_points_y

測試點的 y 坐標

poly_offsets

每個多邊形中第一個環的起始索引

poly_ring_offsets

每個環中第一個點的開始索引

poly_points_x

x closed-coordinate 個多邊形點

poly_points_y

y closed-coordinate 個多邊形點

返回

resultcudf.DataFrame

布爾值的 DataFrame,指示每個點是否落在每個多邊形內。

例子

測試 3 個點是否落在兩個多邊形中

>>> result = cuspatial.point_in_polygon(
    [0, -8, 6.0],                             # test_points_x
    [0, -8, 6.0],                             # test_points_y
    cudf.Series([0, 1], index=['nyc', 'hudson river']), # poly_offsets
    [0, 3],                                   # ring_offsets
    [-10, 5, 5, -10, 0, 10, 10, 0],           # poly_points_x
    [-10, -10, 5, 5, 0, 0, 10, 10],           # poly_points_y
)
# The result of point_in_polygon is a DataFrame of Boolean
# values indicating whether each point (rows) falls within
# each polygon (columns).
>>> print(result)
            nyc            hudson river
0          True          True
1          True         False
2         False          True
# Point 0: (0, 0) falls in both polygons
# Point 1: (-8, -8) falls in the first polygon
# Point 2: (6.0, 6.0) falls in the second polygon

注意輸入係列 x 和 y 不會索引對齊,而是作為順序數組計算。

相關用法


注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cuspatial.point_in_polygon。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。