Skip to content

Single side buffer in R

3 messages · Barry Rowlingson, Arnaud Mosnier

#
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
1 day later
#
What's happened here is that part of the RHS of the buffer (from the
acute angle segment) has wrapped round so far that it has overlapped
with the LHS of the buffer from the first segment. So there's an area
which is both on the LHS of the line and the RHS. What do you want it
to be?

You could just extend the ends of the last segments to infinity (and
beyond!!) and use that to cut the buffer, but an odd little end line
segment could mess this up. Fundamentally I don't think there's a
clear definition of what to do...

You probably have to decide more formally what constitutes the LHS and
RHS of your line segment, but I'm not sure in what terms you can make
this without ambiguity...
On Tue, Dec 29, 2015 at 8:05 PM, Arnaud Mosnier <a.mosnier at gmail.com> wrote:
#
I solved part of my problem cutting my original line into segments each
time the line makes an angle larger than a defined value, thus, I have now
relatively straight segments on which I can use my previous methodology
(buffer cutting buffer).
But still, I would appreciate if someone can suggest a solution in order to
obtain directly (i.e without using the previous trick) a left or right
buffer based on a SpatialLine.

Thanks and Happy New Year !!!

Arnaud

2015-12-31 7:45 GMT-05:00 Barry Rowlingson <b.rowlingson at lancaster.ac.uk>: