r - 如何取消列出空间对象并在 R 中完全绘制

标签 r list geospatial spatial

我将空间线作为“列表”:

> 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/

相关文章:

r - 在 RStudio 中进行快捷编织时无法打开连接

python 在列表列表中查找给定节点的所有邻居

r - 为什么 R 中的回归删除因子变量的索引 1?

r - 如何通过RDCOMClient将VBA "with"函数结构解释为R代码?

python - 从列表的给定索引中获取邻居数。给定解决方案的最佳实践或有效性能是什么?

r - 从列表中选择多个元素

coordinates - 将本地平面坐标转换为 WGS84 的概述

从 gis x,y 坐标获取美国邮政编码的算法

Python 测试点是否在矩形中

r - 提取数据帧的行索引,其条目对应于另一个数据帧的行