我有一个包含三个轮廓0.2,0.5和0.95的SpatialLinesDataFrame,并希望能够选择一个单一级别进行进一步计算(例如,over,gIntersect等)。
我尝试使用data@data$level[[1]]
选择第一级但不起作用
class : SpatialLinesDataFrame
features : 3
extent : 11.44765, 11.51037, 62.11384, 62.13572 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0
variables : 1
names : level
min values : 0.2
max values : 0.95
Formal class 'SpatialLinesDataFrame' [package "sp"] with 4 slots
..@ data :'data.frame': 3 obs. of 1 variable:
.. ..$ level: Factor w/ 3 levels "0.2","0.5","0.95": 1 2 3
..@ lines :List of 3
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..@ Lines:List of 6
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:9, 1:2] 11.5 11.5 11.5 11.5 11.5 ...
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:7, 1:2] 11.5 11.5 11.5 11.5 11.5 ...
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:11, 1:2] 11.5 11.5 11.5 11.5 11.5 ...
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:7, 1:2] 11.5 11.5 11.5 11.5 11.5 ...
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:25, 1:2] 11.5 11.5 11.5 11.5 11.5 ...
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:21, 1:2] 11.5 11.5 11.5 11.5 11.5 ...
.. .. .. ..@ ID : chr "C_1"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..@ Lines:List of 10
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:31, 1:2] 11.5 11.5 11.5 11.5 11.5 ...
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:51, 1:2] 11.5 11.5 11.5 11.5 11.5 ...
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:13, 1:2] 11.5 11.5 11.5 11.5 11.5 ...
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:55, 1:2] 11.5 11.5 11.5 11.5 11.5 ...
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:19, 1:2] 11.5 11.5 11.5 11.5 11.5 ...
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:25, 1:2] 11.5 11.5 11.5 11.5 11.5 ...
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:11, 1:2] 11.5 11.5 11.5 11.5 11.5 ...
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:31, 1:2] 11.5 11.5 11.5 11.5 11.5 ...
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:11, 1:2] 11.5 11.5 11.5 11.5 11.5 ...
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:37, 1:2] 11.5 11.5 11.5 11.5 11.5 ...
.. .. .. ..@ ID : chr "C_2"
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..@ Lines:List of 2
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:173, 1:2] 11.4 11.4 11.4 11.4 11.4 ...
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:693, 1:2] 11.5 11.5 11.5 11.5 11.5 ...
.. .. .. ..@ ID : chr "C_3"
..@ bbox : num [1:2, 1:2] 11.4 62.1 11.5 62.1
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "x" "y"
.. .. ..$ : chr [1:2] "min" "max"
..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot
.. .. ..@ projargs: chr "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0"
答案 0 :(得分:1)
split(data, data@data$level)
诀窍:)