Created
January 16, 2018 18:23
-
-
Save jlisic/18c5671106da2076d8d2a261a2148c3d to your computer and use it in GitHub Desktop.
Create a tessellation from a subset of sampled data.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create a tessalation | |
sampleVoronoi <- function(x, sampled,rw=NULL) { | |
require(raster) | |
vor <- tile.list( deldir(x[sampled,1], x[sampled,2],rw=rw) ) | |
vorPoly <- lapply( 1:length(vor) , | |
function(i) { | |
tmp <- cbind( vor[[i]]$x, vor[[i]]$y ) | |
tmp <- rbind( tmp, tmp[1,]) | |
colnames(tmp) <- c('x','y') | |
return( Polygons(list(Polygon(tmp)), ID=i) ) | |
} | |
) | |
vorDat <- x[sampled,] | |
vorDat <- as.data.frame(vorDat) | |
rownames(vorDat) <- sapply(slot(SpatialPolygons(vorPoly), 'polygons'), slot,'ID') | |
return( SpatialPolygonsDataFrame(SpatialPolygons(vorPoly),data=vorDat) ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment