def test_empty(dtype): order, quadtree = cuspatial.quadtree_on_points( cudf.Series([], dtype=dtype), # x cudf.Series([], dtype=dtype), # y *bbox_1, # bbox 1, # scale 1, # max_depth 1, # min_size ) poly_bboxes = cuspatial.polygon_bounding_boxes( cudf.Series(), cudf.Series(), cudf.Series([], dtype=dtype), cudf.Series([], dtype=dtype), ) # empty should not throw intersections = cuspatial.join_quadtree_and_bounding_boxes( quadtree, poly_bboxes, *bbox_1, 1, 1, # bbox # scale # max_depth ) cudf.testing.assert_frame_equal( intersections, cudf.DataFrame({ "poly_offset": cudf.Series([], dtype=np.uint32), "quad_offset": cudf.Series([], dtype=np.uint32), }), )
def _spatialJoinDist(self, ldf, rdf, lName, rName, lTree, polygon, dist): (polyOffset, ringOffset, xPoints, yPoints) = polygon (points, tree) = lTree boundingBox = cuspatial.polygon_bounding_boxes(polyOffset, ringOffset, xPoints, yPoints) joinFilter = cuspatial.join_quadtree_and_bounding_boxes( tree, boundingBox, 0.0, 1.0, 0.0, 1.0, 1.0, 15) joinPolygon = cuspatial.quadtree_point_in_polygon( joinFilter, tree, points, ldf[lName + 'X'], ldf[lName + 'Y'], polyOffset, ringOffset, xPoints, yPoints, ) # https://github.com/rapidsai/cuspatial/issues/284 lGather = ldf.take(points.take( joinPolygon['point_index'])).reset_index(drop=True) rGather = rdf.take(joinPolygon['polygon_index']).reset_index(drop=True) dfConcat = cudf.concat([lGather, rGather], axis=1) dfConcat['distPred'] = False @cuda.jit def distPredFunc(lX, lY, rX, rY, out, dist): i = cuda.grid(1) if i < lX.shape[0]: dX = lX[i] - rX[i] dY = lY[i] - rY[i] dSquare = (dX * dX) + (dY * dY) out[i] = dSquare < (dist * dist) numbaTime = 0.0 if dist > 0.0: startTime = time.time() distPredFunc.forall(dfConcat.shape[0])(dfConcat[lName + 'X'], dfConcat[lName + 'Y'], dfConcat[rName + 'X'], dfConcat[rName + 'Y'], dfConcat['distPred'], dist) endTime = time.time() numbaTime = endTime - startTime dfConcat = dfConcat[dfConcat['distPred']] return (dfConcat, numbaTime)
def test_polygon_join_small(dtype): x_min = 0 x_max = 8 y_min = 0 y_max = 8 scale = 1 max_depth = 3 min_size = 12 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.polygon_bounding_boxes( small_poly_offsets, small_ring_offsets, poly_points_x, poly_points_y, ) 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, 3, 1, 2, 1, 1, 0, 3], dtype=np.uint32), "quad_offset": cudf.Series([10, 11, 6, 6, 12, 13, 2, 2], dtype=np.uint32), }), )
def get_updated_df_quadtree_pip(lat, lon, nodes_df): min_x, min_y, max_x, max_y = (nodes_df["x"].min(), nodes_df["y"].min(), nodes_df["x"].max(), nodes_df["y"].max()) max_depth = 6 min_size = 50 scale = max(max_x - min_x, max_y - min_y) // (1 << max_depth) point_indices, quadtree = cuspatial.quadtree_on_points( nodes_df.x, nodes_df.y, min_x, max_x, min_y, max_y, scale, max_depth, min_size, ) poly_offsets, ring_offsets = cudf.Series([0], index=["selection"]),[0] poly_bboxes = cuspatial.polygon_bounding_boxes( poly_offsets, ring_offsets, lat, lon, ) intersections = cuspatial.join_quadtree_and_bounding_boxes( quadtree, poly_bboxes, min_x, max_x, min_y, max_y, scale, max_depth, ) polygons_and_points = cuspatial.quadtree_point_in_polygon( intersections, quadtree, point_indices, nodes_df.x, nodes_df.y, poly_offsets, ring_offsets, lat, lon, ) return nodes_df.loc[polygons_and_points.point_index]
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), }), )
def test_quadtree_point_in_polygon_small(dtype): x_min = 0 x_max = 8 y_min = 0 y_max = 8 scale = 1 max_depth = 3 min_size = 12 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.polygon_bounding_boxes( small_poly_offsets, small_ring_offsets, poly_points_x, poly_points_y, ) intersections = cuspatial.join_quadtree_and_bounding_boxes( quadtree, poly_bboxes, x_min, x_max, y_min, y_max, scale, max_depth, ) polygons_and_points = cuspatial.quadtree_point_in_polygon( intersections, quadtree, point_indices, points_x, points_y, small_poly_offsets, small_ring_offsets, poly_points_x, poly_points_y, ) cudf.testing.assert_frame_equal( polygons_and_points, cudf.DataFrame({ "polygon_index": cudf.Series( [3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 3], dtype=np.uint32, ), "point_index": cudf.Series( [ 28, 29, 30, 31, 32, 33, 34, 35, 45, 46, 47, 48, 49, 50, 51, 52, 54, 62, 60, ], dtype=np.uint32, ), }), )
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, ) assert_eq( 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, ), }), )