The census bureau doesn\'t provide a nationwide shapefile of public use microdata areas (the smallest geography available on the American Community Survey). I tried combining t
Your problem as you should have guessed is due to the fact that there are duplicate polygon IDs in your object d
.
Indeed, all the polygon IDs in your "shp" files are "0"
. Thus, you used fix.duplicated.IDs = TRUE
to make them different.
This is weird because the taRifx.geo:::rbind.SpatialPolygonsDataFrame
should have fixed it as you set fix.duplicated.IDs = TRUE
. More accurately, the information is transmitted to sp::rbind.SpatialPolygons
which calls the "internal" function sp:::makeUniqueIDs
, which finally uses the function base::make.unique
.
I did not want to see what went wrong in this chain. Alternatively, I advise you to set up yourself the IDs of your polygons, instead of using the fix.duplicated.IDs
option.
To fix it by yourself, replace your for-loop by the following code:
d <- NULL
count <- 0
for ( i in af ){
try( file.remove( z ) , silent = TRUE )
download.file( i , tf , mode = 'wb' )
z <- unzip( tf , exdir = td )
b <- readShapePoly( z[ grep( 'shp$' , z ) ] )
for (j in 1:length(b@polygons))
b@polygons[[j]]@ID <- as.character(j + count)
count <- count + length(b@polygons)
if ( is.null( d ) )
d <- b
else
d <- taRifx.geo:::rbind.SpatialPolygonsDataFrame( d , b )
}
The simple for-loop on j
only changes the ID of each polygon in the object b
before biding it to d
.