luukvdmeer / sfnetworks

Tidy Geospatial Networks in R
https://luukvdmeer.github.io/sfnetworks/
Other
338 stars 20 forks source link

Get network faces/azimuth between connected edges #178

Open idshklein opened 2 years ago

idshklein commented 2 years ago

Lately I have learned about faces, a third component of a spatial planar network. Spatialite documentation expands here. I was wondering how one would get the network faces using sfnetworks, but i do not know where to begin. assuming undirected network, one approach is to take every edge of the network and traversing to the edge which is the righetet/ leftest turn from the edge. However unfortunately, this function doesn't exist in sfnetworks. I'm sure people here have better ideas on how to implement such a feature, which can greatly help in analyzing urban spaces.

agila5 commented 2 years ago

Hi @idshklein and thank you very much for the reference. I briefly checked the link and I think that maybe we can simulate the same structure using the following approach. First, load usual packages

suppressPackageStartupMessages({
  library(sf)
  library(tidygraph)
  library(sfnetworks)
})

Then, load data and compute faces using the edges of the network and lwgeom::st_split

roxel = as_sfnetwork(roxel, directed = FALSE) %>% 
  convert(to_spatial_subdivision, .clean = TRUE) %>%
  st_transform(3857)
#> Warning: to_spatial_subdivision assumes attributes are constant over geometries
bbox = st_as_sfc(st_network_bbox(roxel)) %>% st_buffer(150)
faces <- lwgeom::st_split(bbox, st_geometry(roxel, "edges")) %>% 
  st_collection_extract("POLYGON")

Plot:

par(mar = rep(0, 4))
plot(faces, col = sf.colors(177, alpha = 0.5, categorical = TRUE))
plot(roxel, add = TRUE, cex = 0.7)

Created on 2021-11-07 by the reprex package (v2.0.1)

The light-green area should be f0 while all the other colours represent f1, f2 and so on. There are several limitations at the moment (i.e. no hierarchical structure among the faces, no realistic representation for f0, no way to automatically adjust those faces when modifying the network and so on). What do you think? Could you also suggest an application of these objects in urban spaces analysis? Might help with the implementation.