Skip to contents

Partition coordinates into quantile polygons

Usage

par_cut_coords(x = NULL, y = NULL, quantiles)

Arguments

x

numeric/sf/SpatVector. x-coordinates (if numeric).

y

numeric. y-coordinates.

quantiles

numeric vector. Quantiles.

Value

A SpatVector object with field CGRIDID.

Note

This function is only for two-dimensional points.

Examples

if (FALSE) { # \dontrun{
library(terra)

random_points <-
  data.frame(x = runif(1000, 0, 100), y = runif(1000, 0, 100))
quantiles <- seq(0, 1, length.out = 5L)
qpoly <- par_cut_coords(random_points$x, random_points$y, quantiles)
clustered_points <-
  data.frame(x = rgamma(1000, 1, 1), y = rgamma(1000, 4, 1))

qpoly_c <- par_cut_coords(clustered_points$x, clustered_points$y, quantiles)

par(mfcol = c(1, 2))
plot(qpoly)
plot(qpoly_c)
par(mfcol = c(1, 1))

cvect <- terra::vect(clustered_points, geom = c("x", "y"))
plot(cvect)
plot(qpoly_c, add = TRUE, col = "transparent", border = "red")

qcv <- intersect(cvect, qpoly_c)
table(qcv$CGRIDID)
sum(table(qcv$CGRIDID)) # should be 1000
} # }