解决断开的网络以进行传输分析

时间:2019-01-22 16:30:45

标签: r stplanr

我要遍历多个地址以根据道路距离创建“服务区”或缓冲区。为了尽量减少计算时间,我首先对网络进行缓冲,以减少网络中的节点数。但是,将网络剪切到循环缓冲区通常会导致“孤儿”道路不再连接任何东西。结果是代码无法到达所有节点以计算沿边缘(道路)的距离。我正在寻找一个功能,使我能够删除这些较小的断开连接的网络,以使它们不会引发错误。

Disconnected Networks http://tinypic.com/r/35c3mlu/9

# Convert the road network to  local projection (UTM 18N)
roads_utm <- st_transform(roadsReclass, 2959)

for(r in 1:nrow(Addresses)) {
  row <- Addresses[r,]
  # Coordinates of the address
  st_origin <- st_point(c(row$x,row$y))
  point <- st_sfc(st_origin, crs = 4326)
  point <- st_transform(point, 2959)

  #Create buffer around the address and extract smaller road network
  buffer <- st_buffer(point,10000)
  roads_sub <- st_intersection(buffer, roads_utm)
  roads_sub_sf <- st_sf(geometry = roads_sub)
  roads_sld <- as(roads_sub_sf, 'Spatial')
  roads_sld$length <- line_length(roads_sld)

  #Connect the roads in the network
  network <- overline(roads_sld, attrib='length')

  sln_sub <- SpatialLinesNetwork(network)



# Find the node
  xcoord <- st_coordinates(point)[1]
  ycoord <- st_coordinates(point)[2]
  origin_node <- find_network_nodes(sln_sub, xcoord, ycoord)

  #Get number of nodes to use as an iterator
  nodes <- sln2points(sln_sub)
  nNodes <- length(nodes)

  for(n in 1:nNodes){
    node <- n
    shortRoute <- sum_network_routes(sln_sub, origin_node, node, sumvars = "length")
    if(shortRoute$sum_length < 10000){
      shortRoutes <- rbind(shortRoutes,shortRoute)
    }
  }
}
plot(shortRoutes)

错误:

在structural_properties.c:4597:如果if(shortRoute $ sum_length <10000){,则无法达到某些verticesError:   缺少需要TRUE / FALSE的值

当然,如果有人对R中的服务区域有更好的方法,我也很乐意使用其他方法。

0 个答案:

没有答案