[R-sig-Geo] buffer between points and line shapefiles

Gareth Davies grothered at gmail.com
Tue Apr 10 12:30:14 CEST 2012


Hi,
You can do something like the following:

# Make some points
tmp = matrix(runif(20),ncol=2)
pts=SpatialPoints(tmp) # These are the points

library(rgeos)
pts_buffer=gBuffer(pts,width=0.1,byid=T) # This is the points with a buffer


# Make a 'river'
tmp = matrix(c(0,1, 0,2) ,ncol=2)
tmp2 = Lines( list(Line(tmp)), ID="0")
lne = SpatialLines(list(tmp2)) # This is the river 'line'
lne_buffer=gBuffer(lne,width=0.02) # This is the buffered river

# Plot everything
plot(pts_buffer,col='green')
plot(lne_buffer,add=T,col='blue')
plot(lne,add=T,col='black')
plot(pts,add=T,col='red')

# Find overlaps -- TRUE denotes overlap
# There are various things you could do
point_buffer_intersect_river=over(pts_buffer,lne)
point_intersect_river_buffer=over(pts,lne_buffer)
point_buffer_intersect_river_buffer=over(pts_buffer,lne_buffer)

# Then to get the points that intersect, you can do e.g.
pts[!is.na(point_buffer_intersect_river_buffer)]
# assuming some points do actually intersect



More information about the R-sig-Geo mailing list