r - Number of segments in SpatialLinesDataFrame -
after importing spatial lines dataframe readogr
, determine number of line segments (nodes) in each line. cannot find practical way export lengths vector.
routes@lines
me line slots, how 1 length of each one?
for example, in sample data below, see first line composed of 93 segments, second line composed of 170 segments, third 91 segments, , on.
in end, i'd vector of 1657 numbers representing length of line segments in spatiallinesdataframe
is there quick solution?
> class(routes) [1] "spatiallinesdataframe" attr(,"package") [1] "sp" > str(routes) formal class 'spatiallinesdataframe' [package "sp"] 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"] 2 slots .. .. .. ..@ lines:list of 1 .. .. .. .. ..$ :formal class 'line' [package "sp"] 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"] 2 slots .. .. .. ..@ lines:list of 1 .. .. .. .. ..$ :formal class 'line' [package "sp"] 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"] 2 slots .. .. .. ..@ lines:list of 1 .. .. .. .. ..$ :formal class 'line' [package "sp"] 1 slot .. .. .. .. .. .. ..@ coords: num [1:91, 1:2] -79.9 -79.9 -79.9 -79.9 -79.9 ... .. .. .. ..@ id : chr "2"
based on output structure,
sapply( routes@lines, function (x) dim(x@lines[[1]]@coords)[1] )
Comments
Post a Comment