[R-sig-Geo] Single side buffer in R

Arnaud Mosnier a.mosnier at gmail.com
Tue Dec 29 21:05:38 CET 2015


Dear spatial object users,

Is there a way to make a single side buffer (left or right) based on
SpatialLines?

Generally I use the trick consisting in cutting the buffer with the
expected width with a really small one, but in this case, it does not works
(see below).
I think that a single side buffer tool exists in Geos (but not via rgeos).
Is that kind of function available in another package?

Thanks

Arnaud


### Example

library(rgeos)
library(sp)
coords <- data.frame(matrix(c(rep(seq(0,10),each=2)), ncol=2, byrow=T))
colnames(coords) <- c("X","Y")
coordinates(coords) <- ~ X + Y
spL <- SpatialLines(list(as(coords,"Lines")))
plot(spL)
Buf <- gBuffer(spL, width=2, capStyle="FLAT")
Cut <- gBuffer(spL, width=0.001, capStyle="SQUARE")
out <- disaggregate(gDifference(Buf,Cut))
plot(out, col=c(1,2))
plot(spL, col="blue", add=T, lwd=2) # It works

coords <- data.frame(matrix(c(0,0,1,1,1.5,0,3,3,4,4), ncol=2, byrow=T))
colnames(coords) <- c("X","Y")
coordinates(coords) <- ~ X + Y
spL <- SpatialLines(list(as(coords,"Lines")))
plot(spL)
Buf <- gBuffer(spL, width=2, capStyle="FLAT")
Cut <- gBuffer(spL, width=0.001, capStyle="SQUARE")
out <- disaggregate(gDifference(Buf,Cut))
plot(out, col=c(1,2))
plot(spL, col="blue", add=T, lwd=2) # Now it is broken because the small
buffer does not cut the larger on all its length

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list