美文网首页
R语言sfnetworks包,st_network_join()

R语言sfnetworks包,st_network_join()

作者: youmigo | 来源:发表于2021-09-03 00:27 被阅读0次

    R语言sfnetworks包,st_network_join()#基于节点几何相等的两个空间网络连接

    # Mon Jul 26 17:07:15 2021 -
    
    # 字符编码:UTF-8
    # R 版本:R x64 4.1 for window 11
    # cgh163email@163.com
    # 个人笔记不负责任,拎了个梨🍐🍈
    #.rs.restartR()
    require(sfnetworks)
    rm(list = ls());gc()
    
    st_network_join()#基于节点几何相等的两个空间网络连接
    library(sf, quietly = TRUE)
    
    node1 = st_point(c(0, 0))
    node2 = st_point(c(1, 0))
    node3 = st_point(c(1,1))
    node4 = st_point(c(0,1))
    edge1 = st_sfc(st_linestring(c(node1, node2)))
    edge2 = st_sfc(st_linestring(c(node2, node3)))
    edge3 = st_sfc(st_linestring(c(node3, node4)))
    
    net1 = as_sfnetwork(c(edge1, edge2))
    net2 = as_sfnetwork(c(edge2, edge3))
    
    joined = st_network_join(net1, net2)
    joined
    #> # A sfnetwork with 4 nodes and 4 edges
    #> #
    #> # CRS:  NA
    #> #
    #> # A directed acyclic multigraph with 1 component with spatially explicit edges
    #> #
    #> # Node Data:     4 x 1 (active)
    #> # Geometry type: POINT
    #> # Dimension:     XY
    #> # Bounding box:  xmin: 0 ymin: 0 xmax: 1 ymax: 1
    #>         x
    #>   <POINT>
    #> 1   (0 0)
    #> 2   (1 0)
    #> 3   (1 1)
    #> 4   (0 1)
    #> #
    #> # Edge Data:     4 x 3
    #> # Geometry type: LINESTRING
    #> # Dimension:     XY
    #> # Bounding box:  xmin: 0 ymin: 0 xmax: 1 ymax: 1
    #>    from    to            x
    #>   <int> <int> <LINESTRING>
    #> 1     1     2   (0 0, 1 0)
    #> 2     2     3   (1 0, 1 1)
    #> 3     2     3   (1 0, 1 1)
    #> # … with 1 more row
    ## Plot results.
    oldpar = par(no.readonly = TRUE)
    par(mar = c(1,1,1,1), mfrow = c(1,2))
    plot(net1, pch = 15, cex = 2, lwd = 4)
    plot(net2, col = "red", pch = 18, cex = 2, lty = 3, lwd = 4, add = TRUE)
    plot(joined, cex = 2, lwd = 4)
    par(oldpar)
    
    dev.copy(png, "1.png");dev.off()
    
    
    image.png

    相关文章

      网友评论

          本文标题:R语言sfnetworks包,st_network_join()

          本文链接:https://www.haomeiwen.com/subject/qhsgmltx.html