# NOT RUN {
# 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)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab