sfnetworks | Tidy Geospatial Networks in R | Data Visualization library
kandi X-RAY | sfnetworks Summary
kandi X-RAY | sfnetworks Summary
Tidy Geospatial Networks in R
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of sfnetworks
sfnetworks Key Features
sfnetworks Examples and Code Snippets
Community Discussions
Trending Discussions on sfnetworks
QUESTION
I'm trying to generate a list of nodes on the shortest path between two nodes using st_network_paths()
. However, I only get a single value for the node index in node_path
.
It works with toy data but not real world data. What needs to happen to make the real world, stream network, play ball?
Line data available here
...ANSWER
Answered 2021-Dec-15 at 14:05The problem is that you are trying to compute a path between two different branches in a directed network:
QUESTION
This is my dataset
...ANSWER
Answered 2021-May-04 at 12:52First, since this dataframe contains mainly coordinates in X and Y for shops and customers, I convert them into sf
objects. Two objects for each set.
QUESTION
Im calculating the shortest path between 2 points in sfnetwork my_sfn.
The calculated path consists of graph ids kept in variable paths and I and would like to get geometry (gps values) connected to those ids.
which is done with:
...ANSWER
Answered 2021-Mar-26 at 21:21I solved it by using the index in the last column in data.frame as index for the paths vector
QUESTION
I have a rooted tree with spatially explicit edges (ln_sfnetwork
) with additional edges created by adding a point layer (pt
).
I would like to give all of the edges between each point on the network the same ID so I can calculate the total length of the network between points. I have a manual solution but this has to be done with large datasets > 20,000 points.
...ANSWER
Answered 2021-Feb-03 at 20:41Interesting problem and nice to see sfnetworks
being used on other type of networks than road networks! I gave this some thought. Beware, the answer is long and may be complicated sometimes.
It is clear what you want the output of your example to be, but the example does not cover many different possibilities of how the network structure can look like after blending in the given points. Therefore it is hard to generalize the rules that should be used for merging. But I made some assumptions regarding that:
As far as I understand you want to group edges based on what the first point is that you pass when travelling downstream on the river network. Hence, if the paths downstreams (towards the root of the tree) from edge 1 and edge 2 both pass through point 1 before passing any of the other points, they should be in the same group. All edges from which downstream travelling reaches the root without passing through any of the points should be together in a single group as well.
So the ultimate goal is to assign a group index to each of the edges. In tidygraph
(the library on which sfnetworks
is build), there are several grouping functions that can be applied to either the nodes or edges of the network. Such grouping functions are meant to be used inside tidyverse verbs like mutate()
and filter()
, where the network that is being worked on is known and not needed as an argument to the grouping function. Hence, you can run network %>% mutate(group = group_components())
, without the need to explicitly forward the network as argument to group_components()
.
All nice and well, but as far as I know tidygraph
does not have a grouping function implemented that addresses your problem. That means, we should create our own! I gave it a try. It may not be exactly what you need, but at least it should give you a good starting point to build further on.
The idea is that we first calculate the distances from the nodes that correspond with the points you added to the network, to all nodes in the network. Then, we select for each point a set of nodes such that the travel time from that point to these nodes is lower than from any other point. The edges that connect the nodes in such a set form the group of edges belonging to that point.
I created another example network which covers more possible cases. The first part of the code below is mainly constructing that network. Then we get to writing the custom group function, and finally applying it to my example network, and also to yours.
QUESTION
Friends could help me resolve the following issue:
I am inserting three executable codes below, the first generates a map using sftnetworks
package, showing the route between two locations. In this case, the two locations to generate the map were defined: from = c(df_spec_clust[1, c("Longitude")], df_spec_clust[1, c("Latitude")])
and to = c (df_spec_prop [4, c ("Longitude")], df_spec_prop [4, c ("Latitude")])]
. In the second, I would like to generate the map in Shiny format, but without defining the locations exactly as I did in the first code. I would like them to be selected from the filters I created (Filter 1 and Filter 2). However, I am unable to generate the map. Could you help me ? To show you I managed to generate the map correctly in the third code for the problem in question but using another package (leaflet
). However, I still couldn't think of a way to make it work using the sfnetworks
package. Any help is appreciated.
Thank you!
First code ...ANSWER
Answered 2020-Jul-27 at 13:20You had a problem in selectInput
. You were calling a function to get the Filter1
and Filter2
, but the function needs Filter1
and Filter2
to execute. The following code executes, but it is slow in showing the map. Updating Filter1
and Filter2
gives an updated map, but it takes a few seconds.
A more robust way to define it would be to define the dataframe in a separate function. That will help us define Filter1
and Filter2
, and then we can pass on this information to the plot function. This will eliminate the chances of passing non-existing combinations which has been a problem sometimes.
QUESTION
I would like to generate the map in shiny (attached), however I am having trouble plotting the map from the code below. Could you take a look and help me solve it ??. The shapefile files can be downloaded from the following website: https://github.com/ropensci/stplanr/releases/download/0.6.1/Example.zip
If you do not have the sfnetworks package installed, please check this website: https://github.com/luukvdmeer/sfnetworks
Thank you very much!
...ANSWER
Answered 2020-Jul-15 at 22:12 output$Map <- renderPlot({
plot(net)
plot(r, col = "blue", lwd = 5, add = TRUE)
})
QUESTION
My goal is to generate an object of neighbourhood relationships between spatial lines in a road network. If my data were spatial polygons I could use spdep::poly2nb
to do this, but I'm having trouble working out how to do this for spatial lines.
In the reprex below I try using igraph::as_adjacency_matrix
create an adjacency matrix and then convert that to a neighbours list object using spdep::mat2listw
. But is this the correct way to go?
Once I have the Neighours list I also want to label with the road_id
attribute.
ANSWER
Answered 2020-Jun-01 at 10:49EDITED to show solution in this sfnetworks
issue https://github.com/luukvdmeer/sfnetworks/issues/10
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install sfnetworks
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page