[R-sig-Geo] Subsetted SpatialPolygonsDataFrame cannot writeOGR to ESRI shapefiles
christiaan pauw
cjpauw at gmail.com
Wed Jun 2 17:01:58 CEST 2010
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
>class(SPbluegum)
[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:
>SPbluegumImP=SPbluegum[which(is.na(match(SPbluegum$PROPDESC,DF$Stand.Number_0))==FALSE),c(3,4,6)]
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"
> writeOGR(SPbluegumImp, dsn=paste(outdir,sep=""), layer="BluegumImpMap", driver="ESRI Shapefile")
Error in writeOGR(SPbluegumImp, dsn = paste(outdir, sep = ""), layer =
"BluegumImpMap", :
unknown data type
Please show me where I go wrong
best regards
Christiaan
More information about the R-sig-Geo
mailing list