ToN*_*NoY 2 r list spatial geospatial
我的空格行为'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
... ...
Run Code Online (Sandbox Code Playgroud)
当我想绘制一条线时,我可以将其绘制为
plot(SL1[[1]])
Run Code Online (Sandbox Code Playgroud)
但是如果我想将所有线条绘制在一起,R会抛出一个错误:
> plot(SL1)
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' is a list, but does not have components 'x' and 'y'
Run Code Online (Sandbox Code Playgroud)
我知道我必须取消登记,但在写完之后它仍然是一样的:
SL1<-unlist(SL1)
Run Code Online (Sandbox Code Playgroud)
任何解决方案
您需要将它们全部放入一个SpatialLines对象中.要执行此操作,您需要Lines从列表中的每个SpatialLines项中提取对象,然后可以从中提取单个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 ) ) )
Run Code Online (Sandbox Code Playgroud)
S4班!