我正在使用带有 LINESTRING 几何图形的 .shp 文件,每行都有几个属性。
Simple feature collection with 5979 features and 39 fields
Geometry type: LINESTRING
Dimension: XY
Bounding box: xmin: 334297 ymin: 6277095 xmax: 360375.2 ymax: 6312683
Projected CRS: WGS 84 / UTM zone 19S
Id A1 A2 ... geometry
1 1 1 1 ... LINESTRING (348339.3 628293...
2 2 2 2 ... LINESTRING (343785.3 629153...
3 3 3 3 ... LINESTRING (343926.6 629186...
4 4 4 4 ... LINESTRING (343988.3 629201...
5 5 5 5 ... LINESTRING (344032.6 629212...
我使用下一个代码来查找相交的线并生成新节点。但是用 sfnetwork 做这个我得到一个没有属性的图。
shp.file = st_read("myfile.shp")
graph = st_sf(shp.file) %>%
# Combine LINESTRINGS into a MULTILINESTRING geometry
st_combine() %>%
# Create a node where the MULTILINESTRINGs cross
st_node() %>%
# Cast back to LINESTRINGs
st_cast('LINESTRING') %>%
# Create sfnetwork
as_sfnetwork(directed = F)
A sfnetwork with 6308 nodes and 6085 edges
#
# CRS: WGS 84 / UTM zone 19S
#
# An undirected multigraph with 282 components with spatially explicit edges
#
# Node Data: 6,308 x 1 (active)
# Geometry type: POINT
# Dimension: XY
# Bounding box: xmin: 334297 ymin: 6277096 xmax: 360375.2 ymax: 6312683
x
<POINT [m]>
1 (348339.3 6282939)
2 (348346.9 6282938)
3 (343785.3 6291533)
4 (343791.5 6291546)
5 (343926.6 6291865)
6 (343931.5 6291875)
# ... with 6,302 more rows
#
# Edge Data: 6,085 x 3
# Geometry type: LINESTRING
# Dimension: XY
# Bounding box: xmin: 334297 ymin: 6277095 xmax: 360375.2 ymax: 6312683
from to x
<int> <int> <LINESTRING [m]>
1 1 2 (348339.3 6282939, 348346.9 6282938)
2 3 4 (343785.3 6291533, 343791.5 6291546)
3 5 6 (343926.6 6291865, 343931.5 6291875)
# ... with 6,082 more rows
如何将具有属性的数据框添加到此类图(如 SpatialLineDataframe)?