voronoi.polygons: Calculate Voronoi polygons for a set of points

Description Usage Arguments Details Value Examples

View source: R/voronoi.polygons.r

Description

Calculate Voronoi polygons (or tessellations) from a SpatialPoints* object

Usage

1
voronoi.polygons(x, bounding.polygon = NULL, range.expand = 0.1)

Arguments

x

A SpatialPoints or SpatialPointsDataFrame object

bounding.polygon

If present, this is a SpatialPolygons* object specifying the bounding polygon(s) for the Voronoi polygons. If present, the Voronoi polygons are clipped to the outside bounding polygon of bounding.polygon. The outside bounding polygon is the union of all polygons in bounding.polygon. If this is not present, the Voronoi polygons extend to a rectangle that is range.expand beyond the bounding box of input points in all directions.

range.expand

A length-one or length-two vector of expansion factors for the bounding box of points in x in the horizontal and vertical directions. If length one, it is replicated to length two. Element one is the fraction of the bounding box's horizontal width that is added and subtracted to the horizontal extent of the output polygons. Element two is the fraction of the bounding box's vertical height that is added and subtracted to the vertical extent of the output polygons. Only this parameter's absolute value is used (i.e., all values are made positive). If bounding.polygon is present, this parameter is ignored.

Details

This is a convenience routine for the deldir::deldir function. The hard work, computing the Voronoi polygons, is done by the deldir::deldir and deldir::tile.list functions. See documentation for those functions for details of computations.

This function is convenient because it takes a SpatialPoints* object and returns a SpatialPolygonsDataFrame object.

Value

A SpatialPolygonsDataFrame containing the Voronoi polygons (or tessellations) surrounding the points in x. Attributes of the output polygons are:

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Triangular grid inside a set of polygons
WA.samp <- sss.polygon(WA,100,triangular=TRUE) 

# Voronoi polygons of triangular grid 
WA.tess <- voronoi.polygons(WA.samp)

# Plot 
plot(WA)
plot(WA.tess, add=TRUE, col=rainbow(length(WA.samp)))
plot(WA.samp, add=TRUE, pch=16)

# One way to measure spatial balance: 
# Compare variance of Voronoi polygons to same sized 
# SRS sample.  
WA.bas <- bas.polygon(WA, 100)
WA.srs <- srs.polygon(WA, 100)
WA.bas.tess <- voronoi.polygons(WA.bas)
WA.srs.tess <- voronoi.polygons(WA.srs)
rel.balance <- var(WA.bas.tess$area)/var(WA.srs.tess$area)

# Example clipping to fixed polygon (from @paul-vdb)
## Not run: 
set.seed(101)
pts <- SpatialPoints(cbind(runif(1000), runif(1000)))
smp <- pts[sample(1:length(pts), 10),]
bound.pts <- cbind(c(0.2503111693,  0.5215198166,  0.8074680642,
                    0.9312807075,  0.9047494268,  0.7750409433,
                    0.3033737308,  0.0000000000,  0.0321650835,
                    0.0321650835),
                  c(0.03098592, 0.14595480, 0.03688176,
                    0.25502784, 0.89472650, 1.00000000,
                    0.80334098, 0.52918441, 0.14005896,
                    0.14005896))
bounding.poly <- SpatialPolygons(list(Polygons(list(Polygon(bound.pts)), "b")), as.integer(1))
vor <- SDraw::voronoi.polygons(smp, bounding.poly)
plot(vor)
points(pts, pch = 20)
points(smp, col = "red", pch = 20, cex=2)
plot(bounding.poly, border="blue", lwd=2, add=T)

## End(Not run)

SDraw documentation built on July 8, 2020, 6:23 p.m.