Skip to content
Prev 12786 / 29559 Next

rbind problems with SpatialPolygonsDataFrame

On Tue, 13 Sep 2011, Jonathan Greenberg wrote:

            
There is no equivalent by design. The IDs are what are used to match the 
geometries with the rows of the attribute data (if any), so cannot be 
arbitrary. The user should assign suitable valyes first, it isn't hard, 
just imposes necessary discipline.

In your case I would never extend the list of Polygons objects as you do - 
I would always first count the total number of Polygons objects in the 
list of SpatialPolygons* objects, create a list of the correct length, 
create and assign unique IDs to the input list components, assign to the 
new list, and only then build the output SpatialPolygons* object. This 
avoids the wasteful reallocation of memory each time round the loop.

Hope this clarifies,

Roger