Skip to content
Prev 8408 / 29559 Next

Subsetted SpatialPolygonsDataFrame cannot writeOGR to ESRI shapefiles

Hallo Everybody

I have been using R for a while but I am new to using R on spatial
data. What I want to do seems fairly straightforward to me but for
some reason it doesn't seem to work even after reading a lot of help
files and mail threads. I want to read shapefile containing a town map
and subset it to contain only the polygons that correspond to a
certain field in the data frame. (i.e. selelct those houses in the
town for which I have some other data). I have a unique stand number
in both the dataframe and shapefile.  Then in want to merge some
additional data from the dataframe and export back to a ESRI
shapefile.

I read the shapefiles with readOGR. The resultant object (called
SPbluegum) is a SpatialPolygonsDataFrame
[1] "SpatialPolygonsDataFrame"
attr(,"package")
[1] "sp"

I think where things go wrong is where I try to create a new object
that is a subset of the full town SPDF. My code is:
This works and can be plotted. class() reveals that this too is a
SpatialPolygonsDataFrame but it cannot be written with writeOGR. This
puzzles me since the error message reads:"unknown data type"
Error in writeOGR(SPbluegumImp, dsn = paste(outdir, sep = ""), layer =
"BluegumImpMap",  :
  unknown data type

Please show me where I go wrong

best regards
Christiaan