user18441
user18441

Reputation: 663

How to compute distances along a network in shapefile? in R

I have a river network in a shapefile (class: "SpatialLinesDataFrame"), with some points on it (see picture below).

I would like to compute the distances between points, but along the rivers. I have been searching a lot and I am not able to find any function that allows directly that.

The closest thing I have found is the function "networkdistance" in the package "secrlinear", however I don't manage to transform my shapefile into the format required to use the function (a "linearmask" object).

Any help with this would be extremely appreciated.

Thanks in advance,

Tina.

enter image description here

Upvotes: 3

Views: 2058

Answers (2)

Matt Tyers
Matt Tyers

Reputation: 2215

I know this is an old thread, but just in case someone runs across this in the future: I just released an R package (riverdist) that deals with this issue, and also provides some tools for network editing and data summaries & visualization. It was written with fisheries work in mind, but could probably be applied to what you're working on, or at least that's the hope!

https://cran.r-project.org/web/packages/riverdist/vignettes/riverdist_vignette.html

Sorry this wasn't more timely -

Upvotes: 4

user3291798
user3291798

Reputation: 28

I think we resolved this problem offline: the geographic coordinates (lat/long) of the shapefile needed to be projected before they could be used in secrlinear. That package approximates the linear network and uses igraph functions for distances.

Upvotes: 0

Related Questions