def test_polyline_bounding_boxes_one(dtype):
    result = cuspatial.polyline_bounding_boxes(
        cudf.Series([0]),
        cudf.Series([2.488450, 1.333584, 3.460720], dtype=dtype),
        cudf.Series([5.856625, 5.008840, 4.586599], dtype=dtype),
        0,  # expansion_radius
    )
    assert_eq(
        result,
        cudf.DataFrame({
            "x_min": cudf.Series([1.333584], dtype=dtype),
            "y_min": cudf.Series([4.586599], dtype=dtype),
            "x_max": cudf.Series([3.460720], dtype=dtype),
            "y_max": cudf.Series([5.856625], dtype=dtype),
        }),
    )
def test_polyline_bounding_boxes_empty(dtype):
    result = cuspatial.polyline_bounding_boxes(
        cudf.Series(),
        cudf.Series([], dtype=dtype),
        cudf.Series([], dtype=dtype),
        0,  # expansion_radius
    )
    assert_eq(
        result,
        cudf.DataFrame({
            "x_min": cudf.Series([], dtype=dtype),
            "y_min": cudf.Series([], dtype=dtype),
            "x_max": cudf.Series([], dtype=dtype),
            "y_max": cudf.Series([], dtype=dtype),
        }),
    )
Exemplo n.º 3
0
def run_test_quadtree_point_to_nearest_polyline_small(dtype,
                                                      expected_distances):
    x_min = 0
    x_max = 8
    y_min = 0
    y_max = 8
    scale = 1
    max_depth = 3
    min_size = 12
    expansion_radius = 2.0
    points_x = small_points_x.astype(dtype)
    points_y = small_points_y.astype(dtype)
    poly_points_x = small_poly_xs.astype(dtype)
    poly_points_y = small_poly_ys.astype(dtype)
    point_indices, quadtree = cuspatial.quadtree_on_points(
        points_x,
        points_y,
        x_min,
        x_max,
        y_min,
        y_max,
        scale,
        max_depth,
        min_size,
    )
    poly_bboxes = cuspatial.polyline_bounding_boxes(
        small_ring_offsets,
        poly_points_x,
        poly_points_y,
        expansion_radius,
    )
    intersections = cuspatial.join_quadtree_and_bounding_boxes(
        quadtree,
        poly_bboxes,
        x_min,
        x_max,
        y_min,
        y_max,
        scale,
        max_depth,
    )
    p2np_result = cuspatial.quadtree_point_to_nearest_polyline(
        intersections,
        quadtree,
        point_indices,
        points_x,
        points_y,
        small_ring_offsets,
        poly_points_x,
        poly_points_y,
    )
    cudf.testing.assert_frame_equal(
        p2np_result,
        cudf.DataFrame({
            "point_index":
            cudf.Series(
                [
                    0,
                    1,
                    2,
                    3,
                    4,
                    5,
                    6,
                    7,
                    8,
                    9,
                    10,
                    11,
                    12,
                    13,
                    14,
                    15,
                    16,
                    17,
                    18,
                    19,
                    20,
                    21,
                    22,
                    23,
                    24,
                    25,
                    26,
                    27,
                    28,
                    29,
                    30,
                    31,
                    32,
                    33,
                    34,
                    35,
                    36,
                    37,
                    38,
                    39,
                    40,
                    41,
                    42,
                    43,
                    44,
                    45,
                    46,
                    47,
                    48,
                    49,
                    50,
                    51,
                    52,
                    53,
                    54,
                    55,
                    56,
                    57,
                    58,
                    59,
                    60,
                    61,
                    62,
                    63,
                    64,
                    65,
                    66,
                    67,
                    68,
                    69,
                    70,
                ],
                dtype=np.uint32,
            ),
            "polyline_index":
            cudf.Series(
                [
                    3,
                    3,
                    3,
                    3,
                    3,
                    3,
                    3,
                    2,
                    2,
                    2,
                    2,
                    3,
                    2,
                    2,
                    2,
                    2,
                    3,
                    3,
                    3,
                    3,
                    3,
                    3,
                    3,
                    3,
                    3,
                    3,
                    3,
                    3,
                    3,
                    3,
                    3,
                    3,
                    3,
                    3,
                    3,
                    3,
                    2,
                    2,
                    2,
                    2,
                    2,
                    1,
                    1,
                    1,
                    1,
                    1,
                    1,
                    1,
                    1,
                    1,
                    1,
                    1,
                    1,
                    1,
                    1,
                    1,
                    1,
                    1,
                    1,
                    1,
                    3,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                ],
                dtype=np.uint32,
            ),
            "distance":
            cudf.Series(expected_distances, dtype=dtype),
        }),
    )
Exemplo n.º 4
0
def test_polyline_join_small(dtype):
    x_min = 0
    x_max = 8
    y_min = 0
    y_max = 8
    scale = 1
    max_depth = 3
    min_size = 12
    expansion_radius = 2.0
    points_x = small_points_x.astype(dtype)
    points_y = small_points_y.astype(dtype)
    poly_points_x = small_poly_xs.astype(dtype)
    poly_points_y = small_poly_ys.astype(dtype)
    point_indices, quadtree = cuspatial.quadtree_on_points(
        points_x,
        points_y,
        x_min,
        x_max,
        y_min,
        y_max,
        scale,
        max_depth,
        min_size,
    )
    poly_bboxes = cuspatial.polyline_bounding_boxes(
        small_ring_offsets,
        poly_points_x,
        poly_points_y,
        expansion_radius,
    )
    intersections = cuspatial.join_quadtree_and_bounding_boxes(
        quadtree,
        poly_bboxes,
        x_min,
        x_max,
        y_min,
        y_max,
        scale,
        max_depth,
    )
    cudf.testing.assert_frame_equal(
        intersections,
        cudf.DataFrame({
            "poly_offset":
            cudf.Series(
                [
                    3,
                    1,
                    2,
                    3,
                    3,
                    0,
                    1,
                    2,
                    3,
                    0,
                    3,
                    1,
                    2,
                    3,
                    1,
                    2,
                    1,
                    2,
                    0,
                    1,
                    3,
                ],
                dtype=np.uint32,
            ),
            "quad_offset":
            cudf.Series(
                [
                    3,
                    8,
                    8,
                    8,
                    9,
                    10,
                    10,
                    10,
                    10,
                    11,
                    11,
                    6,
                    6,
                    6,
                    12,
                    12,
                    13,
                    13,
                    2,
                    2,
                    2,
                ],
                dtype=np.uint32,
            ),
        }),
    )
def test_polyline_bounding_boxes_small(dtype):
    result = cuspatial.polyline_bounding_boxes(
        cudf.Series([0, 3, 8, 12]),
        cudf.Series(
            [
                # ring 1
                2.488450,
                1.333584,
                3.460720,
                # ring 2
                5.039823,
                5.561707,
                7.103516,
                7.190674,
                5.998939,
                # ring 3
                5.998939,
                5.573720,
                6.703534,
                5.998939,
                # ring 4
                2.088115,
                1.034892,
                2.415080,
                3.208660,
                2.088115,
            ],
            dtype=dtype,
        ),
        cudf.Series(
            [
                # ring 1
                5.856625,
                5.008840,
                4.586599,
                # ring 2
                4.229242,
                1.825073,
                1.503906,
                4.025879,
                5.653384,
                # ring 3
                1.235638,
                0.197808,
                0.086693,
                1.235638,
                # ring 4
                4.541529,
                3.530299,
                2.896937,
                3.745936,
                4.541529,
            ],
            dtype=dtype,
        ),
        0.5,  # expansion_radius
    )
    assert_eq(
        result,
        cudf.DataFrame(
            {
                "x_min": cudf.Series(
                    [
                        0.8335840000000001,
                        4.5398230000000002,
                        5.0737199999999998,
                        0.53489199999999992,
                    ],
                    dtype=dtype,
                ),
                "y_min": cudf.Series(
                    [
                        4.0865989999999996,
                        1.003906,
                        -0.41330699999999998,
                        2.3969369999999999,
                    ],
                    dtype=dtype,
                ),
                "x_max": cudf.Series(
                    [
                        3.9607199999999998,
                        7.6906739999999996,
                        7.2035340000000003,
                        3.7086600000000001,
                    ],
                    dtype=dtype,
                ),
                "y_max": cudf.Series(
                    [
                        6.3566250000000002,
                        6.153384,
                        1.735638,
                        5.0415289999999997,
                    ],
                    dtype=dtype,
                ),
            }
        ),
    )