Skip to contents

1. Input data

In this article we show how to set up the spatial network for a city before using it for urban river corridor delineation. We work with the OSM data for the city of Bucharest provided by the CRiSp package. See how to get your own OSM data in vignette("getting-osm-data").

We start by loading the OSM data. According to the delineation method, all persistent physical structures need to be considered. Therefore, the network will contain both streets and railways from OSM.

streets <- bucharest$streets
railways <- bucharest$railways

Note: If the city in question contains other surface-level structures that need to be included in the network, such as above-ground metro lines, retrieve them with the appropriate OSM tags following the instructions in vignette("getting-osm-data") and include them here in the network.

2. Setting up the network

After combining the streets and railway lines, we create a network object.

network <- bind_rows(streets, railways) |>
  as_sfnetwork(directed = FALSE)

To be able to use the network for delineation, we need to flatten it (that is, project bridges to the ground surface) and add nodes at all intersections between edges.

network_new <- flatten_network(network)

The function above first identifies unique apparent intersections between edges. Then it injects those points within the edge geometries (linestrings), so that they can be raised as network nodes in the cleaning step.

Note: sfnetworks::st_network_blend cannot be used for this purpose, because this function only adds external points to one edge (the closest one).

3. Network cleaning

We now perform standard cleaning tasks on the network: subdividing edges by adding missing nodes, removing pseudo-nodes and keeping only the main component of the network.

network_cleaned <- clean_network(network_new)

4. Visualise cleaned network

Visualize cleaned network:

p_before <- ggplot() +
  geom_sf(data = st_as_sf(network, "edges"), col = "grey50") +
  geom_sf(data = st_as_sf(network, "nodes"), col = "red", size = 0.7) +
  ggtitle("Network before preprocessing\n") +
  coord_sf(xlim = c(425000, 426000),
           ylim = c(4922200, 4923200),
           expand = FALSE) +
  theme_void()

p_after <- ggplot() +
  geom_sf(data = st_as_sf(network_cleaned, "edges"), col = "grey50") +
  geom_sf(data = st_as_sf(network_cleaned, "nodes"), col = "red", size = 0.7) +
  ggtitle("Network after preprocessing\n") +
  coord_sf(xlim = c(425000, 426000),
           ylim = c(4922200, 4923200),
           expand = FALSE) +
  theme_void()

grid.arrange(p_before, p_after, ncol = 2)

The network before and after preprocessing.