[R-sig-Geo] Generate a multi-ring buffer - Windows 8 - R 3.1.1

Wesley Roberts jwesroberts at gmail.com
Wed Feb 25 07:35:42 CET 2015


Many thanks Robert,

Your suggestions worked a treat.


Wesley

On Wed, Feb 25, 2015 at 6:37 AM, Robert J. Hijmans <r.hijmans at gmail.com>
wrote:

> Wesley,
>
> Your code should work if you change:
>
>   row.names(x.2 at data)<-i
> to
>   row.names(x.2) <- as.character(i)
>
>
> Alternatively you can use raster::bind
> library(raster)
> buff.out <- do.call(bind, buff.list)
>
> Which also allows you to use a much simplified loop:
>
> buff.list <- list()
> for (i in 1:18) {
>     buff.list[i] <- gBuffer(p,width=i*10)
> }
> buff.out <- do.call(bind,buff.list)
>
>
> Robert
>
> On Tue, Feb 24, 2015 at 8:39 AM, Wesley Roberts <jwesroberts at gmail.com>
> wrote:
> > Dear R-Sig_Geo,
> >
> > I would like to create a multi ring buffer around a point. I have not
> been
> > able to find a built in application to do this. So far I have been using
> > gBuffer with increasing widths within a for loop. Each of the individual
> > buffers is then stored in a list. In the past, I have merged multiple
> > SpatialPolygonsDataFrame's by storing each one in a list and then calling
> > do.call with an rbind which has worked perfectly well. Now however I
> > receive the following error
> >
> > Error in validObject(res) :
> >   invalid class “SpatialPolygons” object: non-unique Polygons ID slot
> values
> >
> >
> > Here is some re-producible code to highlight my problem. Any help would
> be
> > greatly appreciated.
> >
> >
> #########################################################################################################
> > library(rgeos)
> > p<-as.data.frame(matrix(741788.1,8294212,ncol=2,nrow=1))
> > names(p)<-c("X","Y")
> > coordinates(p) <- ~X+Y
> > projection(p)<-CRS("+proj=utm +zone=35 +south +datum=WGS84 +units=m
> > +no_defs")
> > buff.list<-list()
> > i=1
> > for (i in 1:18){
> >   x.1<-gBuffer(p,width=i*10)
> >   df<-as.data.frame(matrix(i,ncol=1,nrow=1))
> >   x.2<-SpatialPolygonsDataFrame(x.1, df, match.ID = FALSE)
> >   row.names(x.2 at data)<-i
> >   buff.list[i]<-x.2
> >   i=i+1
> > }
> > buff.out<-do.call(rbind,buff.list)
> >
> #########################################################################################################
> >
> > Many thanks and kind regards,
> > Wesley
> >
> > --
> > Wesley Roberts
> > jwesroberts at gmail.com
> > Cell: +27(0)83 5355 646
> > skype: roberts-w
> >
> > I hear...I forget
> > I see...and I remember
> > I do...and I understand
> > Ancient Chinese Proverb
> >
> >         [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > R-sig-Geo mailing list
> > R-sig-Geo at r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



-- 
Dr Wesley Roberts
jwesroberts at gmail.com
Cell: +27(0)83 5355 646
skype: roberts-w

I hear...I forget
I see...and I remember
I do...and I understand
Ancient Chinese Proverb

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list