[R-sig-Geo] IDvar argument to readShapeLines

Jim Regetz regetz at nceas.ucsb.edu
Fri May 1 09:05:33 CEST 2009


I'm curious why the maptools functions readShapeLines and 
readShapePoints don't take an IDvar argument, even though their internal 
counterparts .shp2LinesDF and .Map2SPDF do? It appears only 
readShapePoly supports custom IDs in the wrapper function.

For lines, I realize I can change the FIDs afterwards using spChFIDs(). 
However, I have found that this doesn't scale well, with processing time 
seemingly O(n^2) with the number of features. It would thus be useful to 
be able to set custom IDs when the data is read in, as this is faster.

As an example, I recently used spChFIDs on a SpatialLinesDataFrame with 
~70000 features, and after 90 minutes it still hadn't completed (I gave 
up :). In contrast, I mimicked the internal code of readShapeLines with 
an added tweak to set IDs, and it took only 2.5 minutes to read the data 
and assign the IDs I specified:

library(maptools)
map <- suppressWarnings(read.shape("foo.shp"))
lyr <- suppressWarnings(maptools:::.shp2LinesDF(map,
   IDs=as.character(map$att.data$LABEL)))

Is there any reason why this might be a bad idea, in general?

Incidentally, my ultimate goal is to read in several such largish 
shapefiles (all with identical attributes) and spRbind them. So in fact 
I don't care so much *what* the IDs are, just that they be unique across 
all the layers so that rbind/spRbind will work. Should I be using a 
different approach altogether (sticking with R-based solutions)?

Thanks,
Jim

------------------------------
James Regetz, Ph.D.
Scientific Programmer/Analyst
National Center for Ecological Analysis & Synthesis
735 State St, Ste 300
Santa Barbara, CA 93101



More information about the R-sig-Geo mailing list