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


Python cuspatial.quadtree_on_points用法及代碼示例

用法:

cuspatial.quadtree_on_points(xs, ys, x_min, x_max, y_min, y_max, scale, max_depth, min_size)

從給定area-of-interest的一組點構造一個四叉樹

邊界框。

參數

xs

每個點的 x 坐標列

ys

每個點的 y 坐標列

x_min

感興趣區域邊界框的lower-left x 坐標

x_max

感興趣區域邊界框的upper-right x 坐標

y_min

lower-left 感興趣區域邊界框的 y 坐標

y_max

upper-right 感興趣區域邊界框的 y 坐標

scale

縮放以應用於每個點與 (x_min, y_min) 的距離

max_depth

最大四叉樹深度

min_size

非葉四叉樹節點的最小點數

返回

result元組(cudf.Series,cudf.DataFrame)
keys_to_pointscudf.Series(dtype=np.int32)

原始點索引的一列排序鍵

四叉樹cudf.DataFrame

輸入點集的完整四叉樹

鑰匙cudf.Series(dtype=np.int32)

一個 int32 列的象限鍵

等級cudf.Series(dtype=np.int8)

四叉樹級別的 int8 列

is_quadcudf.Series(dtype=np.bool_)

一個布爾列,指示節點是四邊形還是葉子

長度cudf.Series(dtype=np.int32)

如果這是非葉象限(即 is_quadTrue ),則此列的值是非葉象限中的子項數。

否則,此列的值是葉象限中包含的點數。

抵消cudf.Series(dtype=np.int32)

如果這是一個非葉象限(即 is_quadTrue ),則該列的值是非葉象限的第一個子象限的位置。

否則,此列的值是葉子象限的第一個點的位置。

注意

  • 交換 min_xmax_x 如果 min_x > max_x
  • 交換 min_ymax_y 如果 min_y > max_y

例子

根據輸入選擇 min_sizescale 的示例:

>>> np.random.seed(0)
>>> points = cudf.DataFrame({
        "x": cudf.Series(np.random.normal(size=120)) * 500,
        "y": cudf.Series(np.random.normal(size=120)) * 500,
    })

>>> max_depth = 3
>>> min_size = 50
>>> min_x, min_y, max_x, max_y = (points["x"].min(),
                                  points["y"].min(),
                                  points["x"].max(),
                                  points["y"].max())
>>> scale = max(max_x - min_x, max_y - min_y) // (1 << max_depth)
>>> print(
        "min_size:   " + str(min_size) + "\n"
        "num_points: " + str(len(points)) + "\n"
        "min_x:      " + str(min_x) + "\n"
        "max_x:      " + str(max_x) + "\n"
        "min_y:      " + str(min_y) + "\n"
        "max_y:      " + str(max_y) + "\n"
        "scale:      " + str(scale) + "\n"
    )
min_size:   50
num_points: 120
min_x:      -1577.4949079170394
max_x:      1435.877311993804
min_y:      -1412.7015761122134
max_y:      1492.572387431971
scale:      301.0

>>> key_to_point, quadtree = cuspatial.quadtree_on_points(
        points["x"],
        points["y"],
        min_x,
        max_x,
        min_y,
        max_y,
        scale, max_depth, min_size
    )

>>> print(quadtree)
    key  level  is_quad  length  offset
0     0      0    False      15       0
1     1      0    False      27      15
2     2      0    False      12      42
3     3      0     True       4       8
4     4      0    False       5     106
5     6      0    False       6     111
6     9      0    False       2     117
7    12      0    False       1     119
8    12      1    False      22      54
9    13      1    False      18      76
10   14      1    False       9      94
11   15      1    False       3     103

>>> print(key_to_point)
0       63
1       20
2       33
3       66
4       19
    ...
115    113
116      3
117     78
118     98
119     24
Length: 120, dtype: int32

相關用法


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