For balancing computational loads, the function uses
the anticlust
package to cluster the input points. The number of clusters
is determined by the num_cluster
argument. Each cluster will have
equal number of points. Grids will be generated based on the cluster
extents. At the lower level, the function uses terra::distance()
function to calculate the Euclidean distance between points.
Arguments
- points_in
sf
orSpatVector
object. Target points of computation.- n_clusters
integer(1). The number of clusters.
Examples
library(terra)
library(anticlust)
data(ncpoints, package = "chopin")
ncp <- terra::vect(
ncpoints, geom = c("X", "Y"),
keepgeom = FALSE, crs = "EPSG:5070"
)
# 2,304 points / 12 = 192 points per cluster
ncpbal <- par_group_balanced(ncp, 12)
ncpbal
#> class : SpatVector
#> geometry : points
#> dimensions : 2304, 1 (geometries, attributes)
#> extent : 1055215, 1830766, 1356003, 1686298 (xmin, xmax, ymin, ymax)
#> coord. ref. : NAD83 / Conus Albers (EPSG:5070)
#> names : CGRIDID
#> type : <num>
#> values : 1
#> 2
#> 1