[R-sig-Geo] Adding new "Polygons" to SpatialPolygons object

Roger Bivand Roger.Bivand at nhh.no
Thu Jun 12 08:31:46 CEST 2008


On Thu, 12 Jun 2008, milton ruser wrote:

> Dear all,
>
> I have a sequence of polygons as the example below. As the number of
> polygons will change every time, I would like to add a new object of class
> "Polygons" to a SpatialPolygons. Look that on the last time I try to add a
> new "Polygons" and get an error. How can I do dat?

Almost there - just catenate the "polygons" slot with the new "Polygons" 
object(s):

my.pols.SpatPol.complete <- SpatialPolygons(c(slot(my.pols.SpatPol.partial,
   "polygons"), list(my.pol3.Sr)))

Roger

>
> Kind regards,
>
> miltinho
>
> -----
>
> require(maptools)
> my.pol1<-cbind(x=c(3,7,7,3,3),y=c(2,2,6,6,2))
> my.pol2<-cbind(x=c(6,9,9,6,6),y=c(4,4,9,9,4))
> my.pol3<-cbind(x=c(7,10,10,7,7),y=c(2,2,8,8,2))
>
>
> my.pol1.Sr <- Polygons(list(Polygon(my.pol1)), ID="1")
> my.pol2.Sr <- Polygons(list(Polygon(my.pol2)), ID="2")
> my.pol3.Sr <- Polygons(list(Polygon(my.pol3)), ID="3")
>
> my.pols.SpatPol.partial <- SpatialPolygons(list(my.pol1.Sr,my.pol2.Sr))
>
> my.pols.SpatPol.complete <- SpatialPolygons(list(my.pols.SpatPol.partial,
> my.pol3.Sr))
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> 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