Skip to content

compute buffer from point shapefile to have shapefile

2 messages · gianni lavaredo, Robert J. Hijmans

#
Gianni,

Here is an example for longitude/latitude data using (together with
the more usual suspects) the geosphere package (recently released to
CRAN).

xy <- cbind(0, seq(-80, 80, by=20))
dist = 1000000  # 500 km
angles = seq(1,360, by=5)

library(geosphere)
crds = list()
for (i in 1:nrow(xy)) {
	d = destPoint(xy[i,], angles, dist)
	crds[[i]] = rbind(d, d[1,])
}

library(sp)
p = lapply(crds, Polygon)
pp = list()
for (i in 1:length(p)) pp[i] = Polygons(p[i], i)
spdf = SpatialPolygonsDataFrame(SpatialPolygons(pp), data.frame(id=1:length(p)))

library(maptools)
data(wrld_simpl)
plot(wrld_simpl)
plot(spdf, add=TRUE, border='red', lwd=2)
points(xy, pch=20, col='blue')






On Mon, Feb 15, 2010 at 5:39 AM, gianni lavaredo
<gianni.lavaredo at gmail.com> wrote: