Hi Benjamin,

I don't know if you have read carefully the help on SpatialPolygonsDataFrame but it is written about the "data" arugment :

"the number of rows in ‘data’ should equal the number of Polygons-class objects in ‘Sr’"

In your example 'spPolys' correspond to 'Sr' and is a SpatialPolygons which length is 1. You should build a SpatialPolygons with length equal to the number of rows of polyData.
The code below should help you :

xx <- mapply (
            FUN=function(x, y) Polygons(list(x), y),
            polyList, paste('FUBAR', 1:length(polyList), sep='.'),
            SIMPLIFY=FALSE)

spPolys <- SpatialPolygons(xx)
polyData <- data.frame (test=1:length(spPolys)) # actually the datayou want to use
dfReturn <- SpatialPolygonsDataFrame (spPolys, polyData, match.ID=FALSE)

Best,

Vlad

-------
Vladislav Navel

SCAN
www.scan-datamining.com

Le 07/03/2012 04:22, Benjamin Stewart a écrit :
I feel like I have done this before, so I am sorry if I have made a stupid
mistake, however, I am out of ideas.

I am trying to make a shapefile out of a list of polygons. I want to
include the a data frame as well, but I can't seem to create a
SpatialPolygons-Class longer than one object. The one object has all the
individual features when I map it, but it is only one object. Here is my
code:

      xx = Polygons(polyList, "FUBAR")
      spPolys = SpatialPolygons(list(xx))
      polyData = (The data frame I want to use)
      dfReturn = SpatialPolygonsDataFrame(spPolys, polyData, match.ID=F)

Any ideas? If I replace the polyData with data.frame(ID = 1) stupid thing
works!

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to