[R] rgeos - gBuffer, width by z-value

Michael Sumner mdsumner at gmail.com
Sat Apr 7 14:54:47 CEST 2012


Just use a loop and collect the results in a list. BTW, R-Sig-Geo is a
special interest group mailing list specifically for these sorts of
questions regarding sp and rgeos packages (which you did not mention).

library(sp)
library(rgeos)


point <- data.frame(x=c(10,20), y=c(10, 10), z = c(2,7))

point_shp <- SpatialPointsDataFrame(point[,1:2],point)

l <- vector("list", nrow(point_shp))
for (i in seq_len(nrow(point_shp))) {
	l[[i]] <- gBuffer(point_shp[i,], width = point_shp[i,]$z, byid=TRUE,
capStyle="ROUND")
}

plot(point_shp, xlim = bbox(point_shp)[1,] + c(-1, 1) *
max(point_shp$z), ylim = bbox(point_shp)[2,] + c(-1, 1) *
max(point_shp$z))
invisible(lapply(l, plot, add = TRUE))

Cheers, Mike.

On Sat, Apr 7, 2012 at 9:14 PM, Omphalodes Verna
<omphalodes.verna at yahoo.com> wrote:
> Dear list!
>
> I have problem with buffer size (width) in package rgeos. I would like to expand given geometry (points) to specified width based on the z value from attribute table. Here is example:
>
> point <- data.frame(x=c(10,20), y=c(10, 10), z = c(2,7))
>
> point_shp <- SpatialPointsDataFrame(point[,1:2],point)
>
> plot(point_shp, xlim = c(0,30), ylim = c(0,20))
> plot(gBuffer(point_shp, width = 5, byid=TRUE, capStyle="ROUND"), add = TRUE, col = "red")
> plot(gBuffer(point_shp, width = point_shp at data$z, byid=TRUE, capStyle="ROUND"), add = TRUE, col = "green")
>
>
> 'gBuffer' function ''take into account'' always only first line/cell from table. Any suggestion?
>
> Thanks a lot,
>
> OV
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Michael Sumner
Institute for Marine and Antarctic Studies, University of Tasmania
Hobart, Australia
e-mail: mdsumner at gmail.com



More information about the R-help mailing list