我的空格行为'list':
> SL1
[[1]]
class : SpatialLines
nfeatures : 1
extent : 253641, 268641, 2621722, 2621722 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=46 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0
[[2]]
class : SpatialLines
nfeatures : 1
extent : 253641, 268641, 2622722, 2622722 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=46 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0
[[3]]
class : SpatialLines
nfeatures : 1
extent : 253641, 268641, 2623722, 2623722 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=46 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0
... ...
当我想绘制一条线时,我可以将其绘制为
plot(SL1[[1]])
但是如果我想将所有的线条一起绘制,R会抛出一个错误:
> plot(SL1)
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' is a list, but does not have components 'x' and 'y'
我知道我必须取消上市,但在写完之后它仍然保持不变:
SL1<-unlist(SL1)
任何解决方案??
答案 0 :(得分:6)
您需要将它们全部放入一个SpatialLines
对象中。为此,您需要从列表中的每个SpatialLines项中提取Lines
个对象,然后可以从中提取单个lines
对象,然后您可以使用此列表将它们重新组合为单个SpatialLines对象:
# Get the Lines objects which contain multiple 'lines'
ll0 <- lapply( SL1 , function(x) `@`(x , "lines") )
# Extract the individual 'lines'
ll1 <- lapply( unlist( ll0 ) , function(y) `@`(y,"Lines") )
# Combine them into a single SpatialLines object
Sl <- SpatialLines( list( Lines( unlist( ll1 ) , ID = 1 ) ) )
S4课程!