I would like to merge multiple SpatialPolygonDataFrame
s into one.
For Belgium & the Netherlands this works OK using maptools
' spRbind
:
td <- tempdir()
bel <- getData("GADM", country="BEL", level=1, path=td)
nld <- getData("GADM", country="NLD", level=1, path=td)
row.names(nld) <- paste("nld", row.names(nld), sep="_")
row.names(bel) <- paste("bel", row.names(bel), sep="_")
library(maptools)
bel_nld <- spRbind(bel, nld)
plot(bel_nld)
However, in my case I would like to merge the province outlines for both Belgium & the Netherlands, ie
td <- tempdir()
bel <- getData("GADM", country="BEL", level=2, path=td)
nld <- getData("GADM", country="NLD", level=1, path=td)
row.names(nld) <- paste("nld", row.names(nld), sep="_")
row.names(bel) <- paste("bel", row.names(bel), sep="_")
library(maptools)
bel_nld <- spRbind(bel, nld)
plot(bel_nld)
but then I get the error message "Error in rbind(deparse.level, ...) : numbers of columns of arguments do not match"
Would anybody know how to resolve this, and obtain the provincial outlines of Belgium & the Netherlands in one SpatialPolygonDataFrame
?
nld
only has names up to level 1, butbel
has level 1 and level 2 names. If you just want a name for each region, drop all the other columns and create two spdfs with aname
column...