Skip to content

invalid class “SpatialPolygons” object: non-unique Polygons ID slot values

4 messages · Roger Bivand, Agustin Lobo, Edzer Pebesma

#
Hi!

I've got the "invalid class ?SpatialPolygons? object: non-unique
Polygons ID slot values"
error at trying to use rbind() (or spRbind()) with two spatial
polygons dataframes that
come from readOGR() of shapefiles.
Not having done this operation in a long while, It took me quite a
long time to remember about the spChFIDs() solution
(i.e. http://r-sig-geo.2731867.n2.nabble.com/rbind-of-SpPolDFs-td5070215.html)
despite the fact that the help page of spRbind() mentions the  spChFIDs-methods.

Could an example in which spChFIDs() has to be run be added to the
Examples of the spRbind help page?
Actually I think that the case in which 2 spatial polygons dataframes
have independently assigned IDs (and thus most often require the
spChFIDs step) is more common than the case of the current example and
many users just remain confused looking at the error "invalid class
?SpatialPolygons? object: non-unique Polygons ID slot values".

Also, could the rbind() help page contemplate the case of sp objects?

Thanks

Agus
#
On Fri, 20 Dec 2013, Agustin Lobo wrote:

            
Does:

library(maptools)
vignette("combine_maptools")

help?

Roger

  
    
#
Had looked into the vignette. No, it does not really help. spRbind() is only
mentioned in "2.1 Dissolving Polygons" and not in "3.1 Combining
Positional Data".
Including an example where the  "non-unique Polygons ID slot values" occurs in
section 3.1. and the way to fix it using spRbind() would be very helpful. But
having the same example in the help page also would be even better.
I also find the Note
"2. some rbind can accept objects with duplicated IDs,..."
in the spRbind help page very confusing, as it is vague and the rbind
help page does not mention spatial objects at all.

The error I mention is frequent when combining SpPolDF objects that
come from  imported shapefiles
and is probably rare in "only R" processing chains.

Thanks for caring about this.

Agus
On Fri, Dec 20, 2013 at 8:14 PM, Roger Bivand <Roger.Bivand at nhh.no> wrote:
#
Looking at the code,

x = rbind(x1, x2, x3, makeUniqueIDs = TRUE)

ought to work, but I haven't tried.

You are right that neither ?rbind nor ?rbind.SpatialPolygons tells you
about this.
On 12/21/2013 12:16 PM, Agustin Lobo wrote: