Finds which points sit in a box, or near another point.
Methods
See also
Other index:
RTree,
ga_envelope(),
ga_knn_join(),
ga_set_thread_pool(),
ga_sparse_dwithin(),
ga_sparse_knn()
Examples
fp <- system.file("shape/nc.shp", package = "sf")
nc <- as.data.frame(read_shapefile(fp))
pts <- ga_centroid(nc$geometry)
idx <- KDTree$new(pts)
# every centroid within half a degree of every other
head(as.vector(idx$within(pts, 0.5)), 3)
#> <list_of<double>[3]>
#> [[1]]
#> [1] 1 2 18 19 34
#>
#> [[2]]
#> [1] 1 2 3 18
#>
#> [[3]]
#> [1] 2 3 10 23
#>
# a single lookup is an array of one
as.vector(idx$within(ga_xy(-78.6, 35.8), 0.5))[[1]]
#> [1] 24 30 37 54