按线 ID 将空间点属性附加到空间线数据帧

Appending Spatial Points Attributes to Spatial Lines Data Frame by Line ID

GIS 爱好者的问题。我有两个 sp 对象。空间线数据框(作为 OS 道路矢量的裁剪版本)和空间点数据框(数据来自英国警察数据网站)。我使用 snapPointsToLines 函数为 nearest_line_id.

创建了具有新属性的第三个空间点数据框

如何将第三个数据框附加回我的空间线数据框,以便将其用作传单中的颜色属性?

我总体上想做的是将点捕捉到线条作为计数。然后根据传单中的点数为线条着色。因此,如果除了上述解决方案之外还有另一种解决方案来实现这一目标,我会洗耳恭听。

因为我使用的是传单,所以我使用的是特定的 CRS

crs <- sp::CRS('+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0')

然而,要执行 snapPointsToLines 功能,我需要暂时将 crs 转换为笛卡尔坐标,然后再返回(我知道,这很痛苦)。

temp_crs <- sp::CRS("+proj=utm +zone=32 +ellps=WGS84 +datum=WGS84 +units=m +no_defs")

两个数据集的结构正是我所需要的。空间点数据框如下所示:

> str(Points)
Formal class 'SpatialPointsDataFrame' [package "sp"] with 5 slots
  ..@ data       :'data.frame': 191 obs. of  16 variables:
  .. ..$ Crime type     : chr [1:191] "Anti-social behaviour" "Anti-social behaviour" "Anti-social behaviour" "Anti-social behaviour" ...
  .. ..$ Longitude      : num [1:191] 1.3 1.31 1.34 1.35 1.37 ...
  .. ..$ Latitude       : num [1:191] 51.4 51.3 51.4 51.4 51.3 ...
  .. ..$ n              : int [1:191] 1 1 1 1 1 3 1 3 4 1 ...
  .. ..$ objectid       : Factor w/ 380 levels "1","10","100",..: 50 50 50 50 50 50 50 50 50 50 ...
  .. ..$ lad17cd        : Factor w/ 380 levels "E06000001","E06000002",..: 143 143 143 143 143 143 143 143 143 143 ...
  .. ..$ lad17nm        : Factor w/ 380 levels "Aberdeen City",..: 329 329 329 329 329 329 329 329 329 329 ...
  .. ..$ lad17nmw       : Factor w/ 22 levels "Abertawe","Blaenau Gwent",..: NA NA NA NA NA NA NA NA NA NA ...
  .. ..$ bng_e          : Factor w/ 380 levels "126473","199821",..: 376 376 376 376 376 376 376 376 376 376 ...
  .. ..$ bng_n          : Factor w/ 379 levels "1006584","101094",..: 63 63 63 63 63 63 63 63 63 63 ...
  .. ..$ long           : num [1:191] 1.33 1.33 1.33 1.33 1.33 ...
  .. ..$ lat            : num [1:191] 51.4 51.4 51.4 51.4 51.4 ...
  .. ..$ st_areasha     : num [1:191] 1.03e+08 1.03e+08 1.03e+08 1.03e+08 1.03e+08 ...
  .. ..$ st_lengths     : num [1:191] 56839 56839 56839 56839 56839 ...
  .. ..$ nearest_line_id: Factor w/ 98 levels "1043","1107",..: 48 94 31 80 90 11 61 50 68 4 ...
  .. ..$ snap_dist      : num [1:191] 0.0317 0.0386 0.0317 0.0964 0.0826 ...
  ..@ coords.nrs : num(0) 
  ..@ coords     : num [1:191, 1:2] -35712 -35265 -32984 -31745 -31519 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:191] "142.4" "142.10" "142.17" "142.26" ...
  .. .. ..$ : chr [1:2] "X" "Y"
  ..@ bbox       : num [1:2, 1:2] -38985 5714081 -25310 5720875
  .. ..- 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=utm +zone=32 +ellps=WGS84 +datum=WGS84 +units=m +no_defs +towgs84=0,0,0"

Spatial Lines DataFrame 看起来像这样(在这个 post 中必须将其裁剪):

> str(Clipped_Street)
Formal class 'SpatialLinesDataFrame' [package "sp"] with 4 slots
  ..@ data       :'data.frame': 6271 obs. of  29 variables:
  .. ..$ fictitious: Factor w/ 1 level "false": 1 1 1 1 1 1 1 1 1 1 ...
  .. ..$ identifier: Factor w/ 33642 levels "0002D55A-A91E-41D7-B8ED-973F7562D903",..: 6313 22851 21972 20186 15807 23558 25474 25983 26498 25490 ...
  .. ..$ class     : Factor w/ 7 levels "A Road","B Road",..: 2 3 2 6 3 6 3 3 6 6 ...
  .. ..$ roadNumber: Factor w/ 52 levels "A2","A20","A2033",..: 32 NA 36 NA NA NA NA NA NA NA ...
  .. ..$ name1     : Factor w/ 6320 levels "Abbey Close",..: 5586 2955 5720 1695 2955 99 2955 2955 2082 5720 ...
  .. ..$ name1_lang: Factor w/ 0 levels: NA NA NA NA NA NA NA NA NA NA ...
  .. ..$ name2     : Factor w/ 0 levels: NA NA NA NA NA NA NA NA NA NA ...
  .. ..$ name2_lang: Factor w/ 0 levels: NA NA NA NA NA NA NA NA NA NA ...
  .. ..$ formOfWay : Factor w/ 6 levels "Collapsed Dual Carriageway",..: 5 5 5 5 5 5 5 5 5 5 ...
  .. ..$ length    : int [1:6271] 111 86 66 63 19 41 8 46 45 23 ...
  .. ..$ primary   : Factor w/ 2 levels "false","true": 1 1 1 1 1 1 1 1 1 1 ...
  .. ..$ trunkRoad : Factor w/ 2 levels "false","true": 1 1 1 1 1 1 1 1 1 1 ...
  .. ..$ loop      : Factor w/ 2 levels "false","true": 1 1 1 1 1 1 1 1 1 1 ...
  .. ..$ startNode : Factor w/ 21676 levels "00010DB2-DF39-455B-AA62-C3404539F18A",..: 1194 3350 8606 17475 6530 6530 5161 11442 3186 6852 ...
  .. ..$ endNode   : Factor w/ 24871 levels "00010DB2-DF39-455B-AA62-C3404539F18A",..: 5437 7429 10034 15538 5848 4003 13102 20036 13102 9098 ...
  .. ..$ structure : Factor w/ 1 level "Road In Tunnel": NA NA NA NA NA NA NA NA NA NA ...
  .. ..$ nameTOID  : Factor w/ 7826 levels "osgb4000000029278481",..: 4067 4079 4071 6680 4079 7623 4079 4079 4084 4071 ...
  .. ..$ numberTOID: Factor w/ 52 levels "osgb4000000030880859",..: 29 NA 43 NA NA NA NA NA NA NA ...
  .. ..$ function. : Factor w/ 8 levels "A Road","B Road",..: 2 5 2 4 5 4 5 5 4 5 ...
  .. ..$ objectid  : Factor w/ 380 levels "1","10","100",..: 50 50 50 50 50 50 50 50 50 50 ...
  .. ..$ lad17cd   : Factor w/ 380 levels "E06000001","E06000002",..: 143 143 143 143 143 143 143 143 143 143 ...
  .. ..$ lad17nm   : Factor w/ 380 levels "Aberdeen City",..: 329 329 329 329 329 329 329 329 329 329 ...
  .. ..$ lad17nmw  : Factor w/ 22 levels "Abertawe","Blaenau Gwent",..: NA NA NA NA NA NA NA NA NA NA ...
  .. ..$ bng_e     : Factor w/ 380 levels "126473","199821",..: 376 376 376 376 376 376 376 376 376 376 ...
  .. ..$ bng_n     : Factor w/ 379 levels "1006584","101094",..: 63 63 63 63 63 63 63 63 63 63 ...
  .. ..$ long      : num [1:6271] 1.33 1.33 1.33 1.33 1.33 ...
  .. ..$ lat       : num [1:6271] 51.4 51.4 51.4 51.4 51.4 ...
  .. ..$ st_areasha: num [1:6271] 1.03e+08 1.03e+08 1.03e+08 1.03e+08 1.03e+08 ...
  .. ..$ st_lengths: num [1:6271] 56839 56839 56839 56839 56839 ...
  ..@ lines      :List of 6271
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:8, 1:2] 1.38 1.38 1.38 1.38 1.38 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ 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:5, 1:2] 1.38 1.38 1.38 1.38 1.38 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "2"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:5, 1:2] 1.38 1.38 1.38 1.38 1.38 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "3"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "4"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "5"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "6"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "7"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "8"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "9"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "10"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "11"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "12"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "13"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "14"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "15"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:4, 1:2] 1.38 1.38 1.38 1.38 51.39 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "16"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "17"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:7, 1:2] 1.39 1.39 1.38 1.38 1.38 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "18"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:4, 1:2] 1.38 1.38 1.38 1.38 51.39 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "19"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:6, 1:2] 1.38 1.38 1.38 1.38 1.38 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "20"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "21"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "22"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:6, 1:2] 1.38 1.38 1.38 1.38 1.38 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "23"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:4, 1:2] 1.38 1.38 1.38 1.38 51.39 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "24"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:5, 1:2] 1.38 1.38 1.38 1.38 1.38 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "25"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:9, 1:2] 1.38 1.38 1.38 1.38 1.38 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "26"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:7, 1:2] 1.38 1.38 1.38 1.38 1.38 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "27"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:3, 1:2] 1.39 1.38 1.38 51.39 51.39 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "28"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "29"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:2, 1:2] 1.38 1.38 51.39 51.39
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "30"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:8, 1:2] 1.39 1.38 1.38 1.38 1.38 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "31"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:5, 1:2] 1.38 1.38 1.38 1.38 1.38 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "32"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:14, 1:2] 1.38 1.38 1.38 1.38 1.38 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "33"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:5, 1:2] 1.38 1.38 1.38 1.38 1.38 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "34"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "35"
  .. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
  .. .. .. ..@ Lines:List of 1
  .. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
  .. .. .. .. .. .. ..@ coords: num [1:3, 1:2] 1.38 1.38 1.38 51.39 51.39 ...
  .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
  .. .. .. ..@ ID   : chr "36"
  .. .. [list output truncated]
  ..@ bbox       : num [1:2, 1:2] 1.21 51.31 1.45 51.39
  .. ..- 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 +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"

如何将 Points$nearest_line_idClipped_Streets@Lines 合并。当一个是列而另一个是对象中的列表时?有什么办法可以将属性放在 @data 中吗?非常感谢任何方向。如有必要,很乐意提供更多详细信息。

我想我破解了它。关键是使用 sp::merge 来确保属性被写回点。然后调用 @data 元素。然后就像常规合并一样。

Points<-snapPointsToLines(Clipped_Points, Clipped_Street, maxDist=0.1, withAttrs = TRUE, idField="identifier")

Points_agg<-Points@data %>% group_by( nearest_line_id) %>% tally()

Clipped_Street@data<-sp::merge(Clipped_Street@data,Points_agg,by.x="identifier",by.y="nearest_line_id", all.x=TRUE )

下一个问题是在合并之前或之后合并和拆分数据集并保留空间属性,但我可能会把它放在一个新问题中。