【发布时间】:2017-09-02 23:05:04
【问题描述】:
使用readOGR 导入空间线数据框后,我想确定每条线中线段(节点)的数量。我找不到一种实用的方法来简单地将长度导出为向量。
routes@lines 将带我到线槽,但是如何获得每个槽的长度?
例如,在下面的示例数据中,我们看到第一行由 93 个段组成,第二行由 170 个段组成,第三行由 91 个段组成,以此类推。
最后,我想要一个由 1657 个数字组成的向量,表示 SpatialLinesDataFrame 中线段的长度
有没有快速的解决方案?
> class(routes)
[1] "SpatialLinesDataFrame"
attr(,"package")
[1] "sp"
> str(routes)
Formal class 'SpatialLinesDataFrame' [package "sp"] with 4 slots
..@ data :'data.frame': 1657 obs. of 3 variables:
.. ..$ start_time: Factor w/ 1631 levels "2016/09/09 00:00:02",..: 1 2 3 4 5 6 7 8 9 10 ...
.. ..$ duration : int [1:1657] 786 1248 738 786 651 660 616 889 408 475 ...
.. ..$ difftime :Class 'difftime' atomic [1:1657] 2 4 19 67 92 119 170 202 206 213 ...
.. .. .. ..- attr(*, "units")= chr "secs"
..@ lines :List of 1657
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..@ Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:93, 1:2] -79.9 -79.9 -79.9 -79.9 -79.9 ...
.. .. .. ..@ ID : chr "0"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..@ Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:170, 1:2] -79.9 -79.9 -79.9 -79.9 -79.9 ...
.. .. .. ..@ ID : chr "1"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..@ Lines:List of 1
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:91, 1:2] -79.9 -79.9 -79.9 -79.9 -79.9 ...
.. .. .. ..@ ID : chr "2"
【问题讨论】:
-
谢谢,但这不起作用 -
coords$的末尾应该有什么东西吗? -
是的,成功了!