Replies: 1 comment 2 replies
-
Hi @sraul1. First of all, thank you very much for your question. I've never worked with river networks, and that seems a super interesting problem. I tried reading your question on SO and (for me at least) it isn't easy to connect all the pieces. Would you mind simplifying the question on SO starting from a network with just 3 edges and (re)explain the procedure in that case? Something like this: library(sf)
library(tidygraph)
library(sfnetworks)
library(ggplot2)
n01 = st_sfc(st_point(c(0, 0)))
n02 = st_sfc(st_point(c(2, 1)))
n03 = st_sfc(st_point(c(1, 2)))
n04 = st_sfc(st_point(c(3, 2)))
from = c(1, 2, 2)
to = c(2, 3, 4)
nodes = st_as_sf(c(n01, n02, n03, n04))
edges = data.frame(from = from, to = to)
sfn <- sfnetwork(nodes, edges) %>%
convert(to_spatial_explicit, .clean = TRUE) %E>%
mutate(edgeID = c("a","b","c")) %>%
mutate(dL = c(300, 100, 100))
#> Checking if spatial network structure is valid...
#> Spatial network structure is valid
ggplot()+
geom_sf(
data = sfn %>% st_as_sf("edges"),
aes(color = factor(edgeID), linetype = as.character(dL)),
size = 1.5
) +
geom_sf(data = sfn %>% st_as_sf("nodes"))+
scale_color_brewer(palette = "Paired")+
labs(x = "Longitude", y = "Latitude", color = "EdgeID", linetype = "dL")+
theme_bw() Created on 2021-08-25 by the reprex package (v2.0.0) Sorry for the extra work, but I think that if we solve the simplest case, then it should be easier to generalise the solution to more realistic scenarios. Please also check if the smaller example does make sense. |
Beta Was this translation helpful? Give feedback.
-
I posted this on stackoverflow but thought I would also post here as this seems more active of a space.
I'll leave the more specific question I asked on the stackoverflow post if anyone feels like looking at it, but essentially I was just curious of whether anyone had any vignettes/resources for using sfnetworks/tidygraph for hydrologic and stream network analyses purposes. I had not come across much on the subject. Most developers/users of graph analysis tools are more geared toward road network analyses, and as a result most intros on the subject don't deal with river networks. This makes complete sense given the difference in terms of number of users, but there are key differences between these types of applications (namely all stream networks are rooted trees, with only one direction of movement). Given the tidyverse framework that many people in the earth sciences/ecology/GIS are familiar with, it seems like a nature extension to make use of sfnetworks.
These types of network analysis tools would be pretty heavily utilized by people doing hydrology/ecology/general physical science research (which granted, is not a huge population). Especially those of us trying to keep our GIS/analysis/writing in a single space. Most tools available at the moment for hydrologic network analysis are either wrapped up with an ESRI license (All the subcomponents of the Network Analysis toolboxes; ArcHydro), or are 20+ years old written in some variation of FORTRAN and C (SAGA GIS, GRASS GIS, TauDEM).
I'll add that I am a front end user, the folks on the development side are much appreciate by users like myself who less know how to develop packages, and more just know how to Google well enough to get along.
Beta Was this translation helpful? Give feedback.
All reactions