3

I am trying to find a way to apply a rectangular buffer on my spatial polygon dataframe in R. At the end, I would like to be able to shrink my polygons by specified units on both sides. So far, I have tried gBuffer function from rgeos package. However the issue with gbuffer is that it only takes single argument of width and hence applies a uniform buffer on all sides (like buffer by percentage in qgis). My original polygon file has 1800 shapes. Here is a small dummy set to illustrate the problem in R:

library(rgeos)
# simple example, from scratch: Sr1 = Polygon(cbind(c(1,4,4,1,1),c(1,1,4,4,1))) Sr2 = Polygon(cbind(c(1,4,4,1,1),c(6,6,9,9,6))) Srs1 = Polygons(list(Sr1), "s1") Srs2 = Polygons(list(Sr2), "s2") SpP = SpatialPolygons(list(Srs1,Srs2), 1:2)
#left panel on the figure plot(SpP) plot(gBuffer(SpP, byid=TRUE, width=c(-0.3, -0.3)), add=T)

Here is the output figure:

enter image description here

PS: I am also open to qgis solutions.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.