我将空间线作为“列表”:
> 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'
我知道我要unlist了,但是写完还是一样:
SL1<-unlist(SL1)
有什么解决办法吗??
最佳答案
您需要将它们全部放入一个 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 ) ) )
中四类!
关于r - 如何取消列出空间对象并在 R 中完全绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18023462/