2017-04-07 72 views
1

在導入空間線數據幀與readOGR後,我想確定每行中的線段(節點)的數量。我無法找到一種實際的方法來簡單地將長度作爲矢量輸出。SpatialLinesDataFrame中段的數量

[email protected]會讓我到線槽,但那麼如何得到每一個的長度?

例如,在下面的示例數據中,我們看到第一行由93段組成,第二行由170段組成,第三行由91段組成,依此類推。

最後,我想1657號的表示線段在SpatialLinesDataFrame

長度是否有一個快速的解決方案的矢量?

> class(routes) 
[1] "SpatialLinesDataFrame" 
attr(,"package") 
[1] "sp" 
> str(routes) 
Formal class 'SpatialLinesDataFrame' [package "sp"] with 4 slots 
    [email protected] 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" 
    [email protected] lines  :List of 1657 
    .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots 
    .. .. .. [email protected] Lines:List of 1 
    .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot 
    .. .. .. .. .. .. [email protected] coords: num [1:93, 1:2] -79.9 -79.9 -79.9 -79.9 -79.9 ... 
    .. .. .. [email protected] ID : chr "0" 
    .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots 
    .. .. .. [email protected] Lines:List of 1 
    .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot 
    .. .. .. .. .. .. [email protected] coords: num [1:170, 1:2] -79.9 -79.9 -79.9 -79.9 -79.9 ... 
    .. .. .. [email protected] ID : chr "1" 
    .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots 
    .. .. .. [email protected] Lines:List of 1 
    .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot 
    .. .. .. .. .. .. [email protected] coords: num [1:91, 1:2] -79.9 -79.9 -79.9 -79.9 -79.9 ... 
    .. .. .. [email protected] ID : chr "2" 
+0

感謝,但無法運作的 - 應該有在'COORDS $'到底什麼東西? –

+1

是的,這工作! –

回答

相關問題