I am working with a river network where vegetation surveys were conducted (black dots). I would like to:
calculate the minimum distance between all points and the point highlighted by the red arrow
for every shortest path between a point and "the red-arrow point" record all points located on that path. For example, the shortest path between the point highlighted by a circle goes through the points highlighted by rectangles. Therefore, I would to like to to record the unique ID of the "rectangle points".
I have been trying to use shp2graph and igraph to find a solution but so far I was only able to calculate pairwise distances.
This is what I managed to do so far:
library(igraph) library(shp2graph) library(rgdal) library(tidyverse) #Import rivers and points into R rivers<-readOGR(dsn="/path/to/test_area/",layer="river") points<-readOGR(dsn="/path/to/test_area/",layer="points_all") #Assign the points to the river network ptsxy<-coordinates(points)[,1:2] ptsxy<-cbind(ptsxy[, 1],ptsxy[, 2]) res.nv<-points2network(ntdata=rivers, pointsxy = ptsxy,Detailed=TRUE, ELComputed = TRUE,approach=2,ea.prop = rep(1, 2)) #Convert to igraph object igr2 <-nel2igraph(res.nv[],res.nv[], weight = res.nv[]) #Calculate minimum distances between every pair of points id_num <- as.numeric(res.nv[]) mat_dist<-distances(igr2,v=id_num,to=id_num)
The result is a matrix of minimum distances between points.
Here's a link to the data I am currently using: