Skip to content

Issues importing BIG shapefile - Limitations of R or something else?

4 messages · Roger Bivand, T.D. Rudolph

#
On Sat, 28 Mar 2009, Tyler Dean Rudolph wrote:

            
Thanks! The indications are that coordinates is being passed a numeric 
vector, not a matrix, at:

Line(coords = shape$verts[from[i]:to[i], ])

so if from[i] == to[i], the code as shown converts a single coordinate 
(one row) matrix into a numeric vector (omitted drop=FALSE in "[" method, 
perhaps the most common coding error in S/R).

That is fixable, but a better workaround may be to use readOGR() in rgdal 
rather than readShapeLines() in maptools.

Roger

  
    
#
On Sun, 29 Mar 2009, Tyler Dean Rudolph wrote:

            
Tyler:

Thanks again for a full report. The failure in readShapeLines() was caused 
by a line with only a single coordinate (two, in fact). This isn't a 
problem in the readOGR() code, and will not be in the latest release of 
maptools.

In spatstat, if spatstat.options("checkpolygons") is TRUE, (xrange[2] < 
xrange[1]) and (yrange[2] < yrange[1]) are both expected to hold, and 
cannot, because for single coordinate lines, the min and max are equal.

You have two choices - based on the files you made available, either drop 
the two single coordinate lines:

ncrds <- sapply(slot(roads, "lines"), function(x) sapply(slot(x, "Lines"),
   function(y) nrow(slot(y, "coords"))))
summary(unlist(wh_singleton))
keep <- sapply(ncrds, function(x) all(x > 1))
roads_gt_1 <- roads[keep]
length(slot(roads, "lines"))
length(slot(roads_gt_1, "lines"))
test <- as(roads_gt_1, "psp")

or set checkpolygons to FALSE in spatstat.options(). I'm running the 
former at the moment - deleting the SpatialLinesDataFrame object after 
coercing to SpatialLines would save some memory.

Hope this helps,

Roger