Thanks for help... do anybody also have an idea how to export "object l" (which is "list" class) to .*shp file. I use SpatialPolygons, but output in console is : 
Error in SpatialPolygons(list(l)) : 
  cannot get a slot ("area") from an object of type "list"


Cheers, OV


________________________________
 From: Michael Sumner <mdsumner@gmail.com>

Cc: "r-help@r-project.org" <r-help@r-project.org> 
Sent: Saturday, April 7, 2012 2:54 PM
Subject: Re: [R] rgeos - gBuffer, width by z-value

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

> 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@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@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@gmail.com
	[[alternative HTML version deleted]]

