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 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 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, ), }), )