Skip to contents

This function partitions a region into Voronoi polygons that completely overlap it. Each polygon has a random center. The function is essentially a wrapper for spatSample() and voronoi().

Usage

# S4 method for class 'GRaster'
rvoronoi(x, size = 100, seed = NULL)

# S4 method for class 'GVector'
rvoronoi(x, size = 100, seed = NULL)

Arguments

x

A GRaster or GVector used to constrain the location of random points used to create the tesselation.

size

Numeric integer or integer: Number of polygons.

seed

Numeric integer, integer, or NULL (default): Value used as a random seed. If NULL, a random seed will be generated by GRASS.

Value

A GVector.

Examples

if (grassStarted()) {

# Setup
library(sf)

# Example vectors
madDypsis <- fastData("madDypsis") # points
madCoast4 <- fastData("madCoast4") # polygons

# Convert sf vectors to GVectors
dypsis <- fast(madDypsis)
coast4 <- fast(madCoast4)
ant <- coast4[coast4$NAME_4 == "Antanambe"]

# Delaunay triangulation
dypsisDel <- delaunay(dypsis)
plot(dypsisDel)
plot(dypsis, pch = 1, col = "red", add = TRUE)

# Voronoi tessellation
vor <- voronoi(dypsis)
plot(vor)
plot(dypsis, pch = 1, col = "red", add = TRUE)

# Random Voronoi tessellation
rand <- rvoronoi(coast4, size = 100)
plot(rand)

}