Description Usage Arguments Details Value Examples
View source: R/voronoi.polygons.r
Calculate Voronoi polygons (or tessellations) from a
SpatialPoints*
object
1 | voronoi.polygons(x, bounding.polygon = NULL, range.expand = 0.1)
|
x |
A |
bounding.polygon |
If present, this is a |
range.expand |
A length-one or length-two vector of expansion
factors for the bounding box
of points in |
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.
A SpatialPolygonsDataFrame
containing the Voronoi polygons
(or tessellations) surrounding the points in x
. Attributes of the
output polygons are:
x : the horizontal coordinate of the tessellation's defining point
y : the vertical coordinate of the tessellation's defining point
area : area of tessellation, in units of x
's projection.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.