I am trying to create an empty SpatialLines object. With polygons it is easy:
SpatialPolygons(list())
For spatial lines this does not work:
SpatialLines(LinesList = list())
Error in bb[1, ] : incorrect number of dimensions
SpatialLines(LinesList = Lines(list(),ID = "a"))
Error in as.list.default(X) :
no method for coercing this S4 class to a vector
SpatialLines(LinesList = Lines(slinelist = Line(coords = cbind(x = c(), y = c())), ID = c()))
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘coordinates’ for signature ‘"NULL"’
Does someone know how it I could create an empty SpatialLines object?
Workaround
I found a workaround which is maybe not the best way of doing it. I generates a spatial line with no length:
SpatialLines(list(Lines(Line(coords = cbind(x = c(0,0), y = c(0,0))), ID = "A")))