Hi,
I'm a R new user and this is also my first post on this mailing list.
I'm currently working on several project with R and I still have not found
a solution for one :
To be concise I'm working with shapefiles representing on a delimited area :
- sewage plant (SpatialPointsDataFrame)
- water quality measurement stations (SpatialPointsDataFrame)
- hydrographic network (SpatialLineDataFrame)
What I want to do is to calculate the distance between each sewage stations
and each measurement stations following the river route.
For now, I have snapped all my points on the river and created a new layer
with both type of point (sewage stations and measurement) in order to split
the lines by the point layer.
I'm looking for a way to get a kind of distance's matrix.
Does anybody has already worked on a similar project ? I'm kind of lost
with all the R packages and functions so any pistes or proposals or idea
will be greatly appreciate.
PS : As I said this is my first post. If I'm not clear about my issue or if
I'm not respecting any posting rules don't hesitate to tell me about.
Cheers
Tristan Bourgeois
Hydromorphologist
Water Agency of Seine-Normandie Basin
[[alternative HTML version deleted]]
Hi Tristan,
I recently had to do something similar (calculating distance to the next
downstream point), and I was not able to find a solution with R that would
deal with the direction of the flow. Perhaps someone who has deeper
understanding of packages such as iGraph etc. might be able to find a
solution, but I wasn't.
I solved the problem with ArcMap, using HydroTools extension, where you
need to define a geometric network that has a direction, and then the
calculation is pretty straightforward with HydroTools (let me know if you
need more info).
I would prefer to have a scripted solution in an open-source software, but
this worked for me in any case. If anyone has a better way for solving
this, I would love to see how!
Cheers,
Mirza.
Dear Tristan,
no R solution, but maybe a starting point: You can check out the Grass
GIS tool v.net.distance
(https://grass.osgeo.org/grass72/manuals/v.net.distance) what should
help you. GRASS tools can also be integrated in R via the rgrass7 package.
Good luck!
Flo
Am 25.01.2017 um 11:02 schrieb Tristan Bourgeois:
Hi,
I'm a R new user and this is also my first post on this mailing list.
I'm currently working on several project with R and I still have not found
a solution for one :
To be concise I'm working with shapefiles representing on a delimited area :
- sewage plant (SpatialPointsDataFrame)
- water quality measurement stations (SpatialPointsDataFrame)
- hydrographic network (SpatialLineDataFrame)
What I want to do is to calculate the distance between each sewage stations
and each measurement stations following the river route.
For now, I have snapped all my points on the river and created a new layer
with both type of point (sewage stations and measurement) in order to split
the lines by the point layer.
I'm looking for a way to get a kind of distance's matrix.
Does anybody has already worked on a similar project ? I'm kind of lost
with all the R packages and functions so any pistes or proposals or idea
will be greatly appreciate.
PS : As I said this is my first post. If I'm not clear about my issue or if
I'm not respecting any posting rules don't hesitate to tell me about.
Cheers
Hi Mirza,
Thanks for your quick answer.
Actually I don't want to calculate distance between a point and the next
downstream one.
For example, if there are 4 sewage plant on a river and 7 measurment
stations,I want the distance between each sewage plant and each station.
(water pollution dispersion calculation).
So the flow direction is not that important in my case. The difficulty is
to get the distance between a point and another one following the river
polyline.
In your case, you can add a raster layer with elevation values ans extract
the elevation for each point of your layer. Then, for each polyline it is
possible to define a flow direction.
Hope it will help you.
2017-01-25 11:57 GMT+01:00 Mirza Cengic <mirzaceng at gmail.com>:
Hi Tristan,
I recently had to do something similar (calculating distance to the next
downstream point), and I was not able to find a solution with R that would
deal with the direction of the flow. Perhaps someone who has deeper
understanding of packages such as iGraph etc. might be able to find a
solution, but I wasn't.
I solved the problem with ArcMap, using HydroTools extension, where you
need to define a geometric network that has a direction, and then the
calculation is pretty straightforward with HydroTools (let me know if you
need more info).
I would prefer to have a scripted solution in an open-source software, but
this worked for me in any case. If anyone has a better way for solving
this, I would love to see how!
Cheers,
Mirza.
Tristan Bourgeois
[[alternative HTML version deleted]]
Hi Mirza,
Thanks for your quick answer.
Actually I don't want to calculate distance between a point and the next
downstream one.
For example, if there are 4 sewage plant on a river and 7 measurment
stations,I want the distance between each sewage plant and each station.
(water pollution dispersion calculation).
So the flow direction is not that important in my case. The difficulty is
to get the distance between a point and another one following the river
polyline.
In your case, you can add a raster layer with elevation values ans extract
the elevation for each point of your layer. Then, for each polyline it is
possible to define a flow direction.
Hope it will help you.
2017-01-25 11:57 GMT+01:00 Mirza Cengic <mirzaceng at gmail.com>:
Hi Tristan,
I recently had to do something similar (calculating distance to the next
downstream point), and I was not able to find a solution with R that
would
deal with the direction of the flow. Perhaps someone who has deeper
understanding of packages such as iGraph etc. might be able to find a
solution, but I wasn't.
I solved the problem with ArcMap, using HydroTools extension, where you
need to define a geometric network that has a direction, and then the
calculation is pretty straightforward with HydroTools (let me know if you
need more info).
I would prefer to have a scripted solution in an open-source software,
but
this worked for me in any case. If anyone has a better way for solving
this, I would love to see how!
Cheers,
Mirza.
--
Tristan Bourgeois
[[alternative HTML version deleted]]
----------------------------------------------------------------------------------
Jason Romine, Ph.D.
Fish and Wildlife Biologist
U.S. Fish & Wildlife Service
Mid-Columbia River National Wildlife Refuge Complex
64 Maple St
Burbank, WA 99323
Cell: 509-792-0123
https://www.fws.gov/mcriver/
Projects, publications, CV <https://jasongromine.wordpress.com/>
----------------------------------------------------------------------------------
[[alternative HTML version deleted]]
Tristan,
if I understand you right you just want to calculate the distances. So
no hydro stuff like accumulation flow directions etc.? As well as no
diffusion modeling of the pollutants.
Most of the traditional vector based GIS stuff is packed into the rgeos
package. So you might calculated the distances along a graph like in the
following paste and copy snippet.
cheers Chris
library(rgeos)
library(sp)
# just for visualisation
r <- raster(nrows=6, ncols=7, xmn=0, xmx=7, ymn=0, ymx=6, crs="+proj=utm
+units=m")
r[] <- c(1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0,
1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0,
1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0)
# river line
line
<-SpatialLines(list(Lines(Line(cbind(c(5.5,1.5,4.5),c(1.5,5.5,5.5))),
ID="line")))
# points
p1 <-as.data.frame(cbind(4.5,2.5))
p2 <-as.data.frame(cbind(2.5,4.5))
p3 <-as.data.frame(cbind(2.1,4.5))
p4 <-as.data.frame(cbind(3.5,5.5))
p5 <-as.data.frame(cbind(3.5,5.7))
sp::coordinates(p1) <- ~V1+V2
sp::coordinates(p2) <- ~V1+V2
sp::coordinates(p3) <- ~V1+V2
sp::coordinates(p4) <- ~V1+V2
sp::coordinates(p5) <- ~V1+V2
projection(line)<-projection(point)
plot(r)
plot(line,add=TRUE)
plot(p1,add=TRUE)
plot(p2,add=TRUE)
plot(p3,add=TRUE,col="red")
plot(p4,add=TRUE)
plot(p5,add=TRUE,col="red")
# calculate distance along the line
rgeos::gProject(spgeom = line, sppoint = p1)
rgeos::gProject(spgeom = line, sppoint = p2)
rgeos::gProject(spgeom = line, sppoint = p4)
# note if the point is not near the line it is caluclated orthogonal
rgeos::gProject(spgeom = line, sppoint = p3)
rgeos::gProject(spgeom = line, sppoint = p5)
Hi Mirza,
Thanks for your quick answer.
Actually I don't want to calculate distance between a point and the next
downstream one.
For example, if there are 4 sewage plant on a river and 7 measurment
stations,I want the distance between each sewage plant and each station.
(water pollution dispersion calculation).
So the flow direction is not that important in my case. The difficulty is
to get the distance between a point and another one following the river
polyline.
In your case, you can add a raster layer with elevation values ans extract
the elevation for each point of your layer. Then, for each polyline it is
possible to define a flow direction.
Hope it will help you.
2017-01-25 11:57 GMT+01:00 Mirza Cengic <mirzaceng at gmail.com>:
Hi Tristan,
I recently had to do something similar (calculating distance to the next
downstream point), and I was not able to find a solution with R that
would
deal with the direction of the flow. Perhaps someone who has deeper
understanding of packages such as iGraph etc. might be able to find a
solution, but I wasn't.
I solved the problem with ArcMap, using HydroTools extension, where you
need to define a geometric network that has a direction, and then the
calculation is pretty straightforward with HydroTools (let me know if you
need more info).
I would prefer to have a scripted solution in an open-source software,
but
this worked for me in any case. If anyone has a better way for solving
this, I would love to see how!
Cheers,
Mirza.
--
Tristan Bourgeois
[[alternative HTML version deleted]]
Dr Christoph Reudenbach, Philipps-University of Marburg, Faculty of Geography, GIS and Environmental Modeling, Deutschhausstr. 10, D-35032 Marburg, fon: ++49.(0)6421.2824296, fax: ++49.(0)6421.2828950, web: gis-ma.org, giswerk.org, moc.environmentalinformatics-marburg.de