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

R语言sfnetworks包,node_X() node_Y()

作者: youmigo | 来源:发表于2021-09-05 13:55 被阅读0次

R语言sfnetworks包,node_X() node_Y() node_Z() node_M() # 查询节点坐标

# Sat Jul 31 00:37:01 2021 edit
# 字符编码:UTF-8
# R 版本:R 4.1 x64 for window 11
# cgh163email@163.com
# 个人笔记不负责任,拎了个梨🍐🍈
#.rs.restartR()
require(sfnetworks)
rm(list = ls());gc()

node_X() node_Y() node_Z() node_M()
# 查询节点坐标
library(sf, quietly = TRUE)
library(tidygraph, quietly = TRUE)

#创建一个网络。
net = as_sfnetwork(roxel)

# Use query function in a filter call.
filtered = net %>%
  activate("nodes") %>%
  filter(node_X() > 7.54)

oldpar = par(no.readonly = TRUE)
par(mar = c(1,1,1,1))
plot(net, col = "grey")
plot(filtered, col = "red", add = TRUE)
par(oldpar)
dev.copy(png, "1.png");dev.off()
#在mutate调用中使用查询函数。
net %>%
  activate("nodes") %>%
  mutate(X = node_X(), Y = node_Y())
#> # A sfnetwork with 701 nodes and 851 edges
#> #
#> # CRS:  EPSG:4326
#> #
#> # A directed multigraph with 14 components with spatially explicit edges
#> #
#> # Node Data:     701 x 3 (active)
#> # Geometry type: POINT
#> # Dimension:     XY
#> # Bounding box:  xmin: 7.522622 ymin: 51.94151 xmax: 7.546705 ymax: 51.9612
#>              geometry     X     Y
#>           <POINT [°]> <dbl> <dbl>
#> 1 (7.533722 51.95556)  7.53  52.0
#> 2 (7.533461 51.95576)  7.53  52.0
#> 3 (7.532442 51.95422)  7.53  52.0
#> 4  (7.53209 51.95328)  7.53  52.0
#> 5 (7.532709 51.95209)  7.53  52.0
#> 6 (7.532869 51.95257)  7.53  52.0
#> # … with 695 more rows
#> #
#> # Edge Data:     851 x 5
#> # Geometry type: LINESTRING
#> # Dimension:     XY
#> # Bounding box:  xmin: 7.522594 ymin: 51.94151 xmax: 7.546705 ymax: 51.9612
#>    from    to name           type                                       geometry
#>   <int> <int> <chr>          <fct>                              <LINESTRING [°]>
#> 1     1     2 Havixbecker S… residen…     (7.533722 51.95556, 7.533461 51.95576)
#> 2     3     4 Pienersallee   seconda… (7.532442 51.95422, 7.53236 51.95377, 7.5…
#> 3     5     6 Schulte-Bernd… residen… (7.532709 51.95209, 7.532823 51.95239, 7.…
#> # … with 848 more rows

image.png

相关文章

网友评论

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

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