[R-sig-Geo] Buffer regions / owin to spatial object
Roger Bivand
Roger.Bivand at nhh.no
Wed Nov 28 22:28:34 CET 2007
On Tue, 27 Nov 2007, Giorgio Guzzetta wrote:
> Hello everybody.
>
> I have a set of points and I want to calculate a buffer region within a
> given distance from these points without using packages requiring other
> software (such as spgrass6). I have used function disc() for each
> point and then union.owin() (both from spatstat) to merge the single
> buffers.
> The result is an object of class owin, but I would need to obtain an
> object representing the polygons enclosing this buffer.
>
> 1) Are there smarter ways to obtain the buffer region (the union.owin is
> very slow when it comes to hundreds of points, as it must be applied to
> only two owin at a time)? It seems there isn't for buffers around
> polygons (as Adrian Baddeley wrote in a recent thread).
If you can move to raster, you can use erode and dilate methods for owin
objects to buffer in and buffer out - these are based on "im" objects. It
will not be quite the same, but the errors for moderate resolution
probably will not be greater than the inaccuracies in polygon boundaries
(where curves are represented as line segments).
library(maptools)
library(spatstat)
set.seed(1)
pts <- runifpoint(20)
grd <- GridTopology(c(0.005, 0.005), c(0.01, 0.01), c(100, 100))
ptsi <- overlay(SpatialGrid(grd), as(pts, "SpatialPoints"))
SGDF <- SpatialGridDataFrame(grd, data=data.frame(pts=rep(NA, 10000)))
SGDF$pts[ptsi] <- 1
pts_im <- as(SGDF, "im")
pts_owin <- as.owin(pts_im)
plot(pts_owin)
plot(pts, add=TRUE)
pts_owin_0.03 <- dilate.owin(pts_owin, r=0.03)
plot(pts_owin_0.03)
plot(pts, add=TRUE)
gets part of the way there, but most likely better routes exist.
>
> 2) If not, how do I convert the owin object into a Spatial object? There
> are many functions doing the inverse, but I couldn't find any doing this
> conversion.
>
You can get from "im" to SpatialGridDataFrame and from "ppp" fo several sp
classes. So if you go with raster, you can retrieve the buffered objects.
Hope this helps,
Roger
> Sorry if the questions are naive... I'm an R beginner :)
>
> Thanks,
> Giorgio Guzzetta
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list