[R-sig-Geo] modifying shpfiles in maptools

Markus Loecher loecher at eden.rutgers.edu
Thu May 24 19:51:14 CEST 2007


Hello,
I am trying to manipulate a shpfile (actually subsetting it) but am 
not getting anywhere. I would like to plot the census blocks of San 
Francisco county (ID = 075) only but the shpfile I have is for all of CA.
So I am executing the following lines of code, where shpfile.CA is 
the big one for CA:

shpfile.CA <- read.shape("bg06_d00.shp", dbf.data=TRUE, verbose=TRUE);
#keep only those entries for SF county:
shpfile.CA$att.data[,"COUNTY"] <- as.character(shpfile.CA$att.data[,"COUNTY"]);
i.keep <- shpfile.CA$att.data[,"COUNTY"] == "075";
shpfile$att.data <- shpfile.CA$att.data[i.keep,];
shpfile$Shapes <- shpfile.CA$Shapes[i.keep];

To me this seems like a correct subsetting of a list, but when I try 
to plot the new, smaller shpfile, I get the error message:
	Error in 1:attr(theMap$Shapes, "nshps") : NA/NaN argument
What foolish mistake am I committing ?

Also, it seems that plot.Map is deprecated. I wished I had an example 
of how to use plot.Spatial instead, with a shpfile...

Thanks!

markus




More information about the R-sig-Geo mailing list