randomise_voronoi: Randomise locations of points based on Voronoi tesselation

View source: R/randomise_voronoi.R

randomise_voronoiR Documentation

Randomise locations of points based on Voronoi tesselation

Description

Randomise locations of points based on Voronoi tesselation

Usage

randomise_voronoi(
  points,
  map,
  randomise_size = 5L,
  from_type = "point",
  to_type = "centroid",
  mask_landscape = FALSE,
  additional_info = FALSE,
  sample_probs = 10^-seq_len(3L),
  max_tries = 3L,
  verbose = 1L
)

Arguments

points

the points to randomise

map

a landscape to use for masking

randomise_size

the pool size for randomisation

from_type

the basis on which to determine distance between "from" and "to" points: one of voronoi, point or centroid

to_type

the basis on which to determine distance between "from" and "to" points: one of voronoi, point or centroid

mask_landscape

should the Voronoi cells be masked using the map before distances are calculated? Has no effect for from_type=to_type="point"

additional_info

option to provide additional columns in the dataframe returned

max_tries

the maximum number of tries before failure

verbose

a positive integer determining how much progress output should be displayed (0=silent)

sample_size

the number of random points to generate within each Voronoi cell

Value

The return value depends on the input points: if the input is an sfc object and additional_info==FALSE, then the output is also an sfc object; if the input is an sf data frame, then the output is also an sf data frame with the random points in the active geometry (which will have the same name as the input); the output is always an sf data frame if additional_info==TRUE, with the randomised points as the active geometry (this will be named geometry if the input is an sfc object, or have the same name as the active geometry in the input if this was an sf data frame)

Examples

xrange <- c(0, 10)
yrange <- c(0, 10)
corners <- tribble(~x, ~y,
                   xrange[1], yrange[1],
                   xrange[2], yrange[1],
                   xrange[2], yrange[2],
                   xrange[1], yrange[2],
                   xrange[1], yrange[1]
)
library("sf")
map <- st_sfc(st_multipolygon(list(list(as.matrix(corners)))))
points <- st_sfc(lapply(1:10, function(x) st_point(runif(2,0,10))))
random <- randomise_voronoi(points, map, additional_info=TRUE)
ggplot(random) +
  geom_sf(aes(geometry=VoronoiCell)) +
  geom_sf(aes(geometry=VoronoiMasked), alpha=0.5) +
  geom_sf(aes(geometry=RandomShift)) +
  geom_sf(aes(geometry=RandomPoint)) +
  theme_void()



ku-awdc/HexScape documentation built on Jan. 10, 2025, 5:24 p.m.