With R I am looking to smooth my Polygon: inter2.csv
code:
inter1 <- read.table("c:/inter2.csv", header=TRUE)
# add a category (required for later rasterizing/polygonizing)
inter1 <- cbind(inter1, cat = rep(1L, nrow(inter1)), stringsAsFactors = FALSE)
# convert to spatial points
coordinates(inter1) <- ~long + lat
# gridify your set of points
gridded(inter1) <- TRUE
# convert to raster
r <- raster(inter1)
# convert raster to polygons
sp <- rasterToPolygons(r, dissolve = T)
plot(sp)
# addition transformation to distinguish well the set of polygons
polys <- slot(sp@polygons[[1]], "Polygons")
require(Hmisc) # for Bezier curve
output <- SpatialPolygons(
Srl = lapply(1:length(polys),
function(x){
p <- polys[[x]]
#applying bezier curve for smoothing polygon edges
px <- slot(polys[[x]], "coords")[,1]
py <- slot(polys[[x]], "coords")[,2]
bz <- bezier(px, py)
slot(p, "coords") <- as.matrix(cbind(bz$x,bz$y))
# create Polygons object
poly <- Polygons(list(p), ID = x)
return(poly)
}),
proj4string = CRS("+init=epsg:4326")
)
# plot
plot(sp, border = "gray", lwd = 2) # polygonize result
plot(output, border = "red", add = TRUE) # smoothed polygons
I get this result:
It's some days I look for the problem without success, can someone help me please?