skeletal mesh - Looking for skeleton or polygon offset algorithm in R -
i found useful links in question an algorithm inflating/deflating (offsetting, buffering) polygons . sorry - no 'net access sos
doesn't work, have implementation of skeleton algorithm in r?
edit: generate deflated polygons in stackoverflow link (top image); or seen on http://en.wikipedia.org/wiki/straight_skeleton .
gbuffer()
, elegant , powerful rgeos package accepts negative values in width
argument, returning spatialpolygons
'shrunk' given amount.
library(sp) library(rgeos) ## create spatialpolygons object set of x-y coordinates (the hard part!) xy2sp <- function(xy, id=null) { if(is.null(id)) id <- sample(1e12, size=1) spatialpolygons(list(polygons(list(polygon(xy)), id=id)), proj4string=crs("+proj=merc")) } xy <- data.frame(x=c(0,2,3,1,0), y=c(0,0,2,2,0)) sp <- xy2sp(xy) ## shrink spatialpolygons object supplying negative width gbuffer() plot(sp) plot(gbuffer(sp, width=-0.2), add=true, border="red")
Comments
Post a Comment