Comments (1)
The "sfnetworks answer" to close this issue:
library(sfnetworks)
library(igraph)
library(tidygraph)
library(sf)
library(ggplot2)
net = as_sfnetwork(roxel, directed = FALSE)
Regarding ggplot, you will still need to extract nodes and edges as sf objects. However, this is fairly easy now since you can do that without activating first, and instead provide "nodes" or "edges" as argument to st_as_sf.
st_as_sf(net, "nodes")
#> Simple feature collection with 701 features and 0 fields
#> geometry type: POINT
#> dimension: XY
#> bbox: xmin: 7.522622 ymin: 51.94151 xmax: 7.546705 ymax: 51.9612
#> CRS: EPSG:4326
#> # A tibble: 701 x 1
#> geometry
#> <POINT [°]>
#> 1 (7.533722 51.95556)
#> 2 (7.533461 51.95576)
#> 3 (7.532442 51.95422)
#> 4 (7.53209 51.95328)
#> 5 (7.532709 51.95209)
#> 6 (7.532869 51.95257)
#> 7 (7.540063 51.94468)
#> 8 (7.53822 51.94546)
#> 9 (7.537673 51.9475)
#> 10 (7.537614 51.94562)
#> # … with 691 more rows
st_as_sf(net, "edges")
#> Simple feature collection with 851 features and 4 fields
#> geometry type: LINESTRING
#> dimension: XY
#> bbox: xmin: 7.522594 ymin: 51.94151 xmax: 7.546705 ymax: 51.9612
#> CRS: EPSG:4326
#> # A tibble: 851 x 5
#> from to name type geometry
#> <int> <int> <fct> <fct> <LINESTRING [°]>
#> 1 1 2 Havixbecker… reside… (7.533722 51.95556, 7.533461 51.95576)
#> 2 3 4 Pienersallee second… (7.532442 51.95422, 7.53236 51.95377, 7.532…
#> 3 5 6 Schulte-Ber… reside… (7.532709 51.95209, 7.532823 51.95239, 7.53…
#> 4 7 8 <NA> path (7.540063 51.94468, 7.539696 51.94479, 7.53…
#> 5 9 10 Welsingheide reside… (7.537673 51.9475, 7.537614 51.94562)
#> 6 11 12 <NA> footway (7.543791 51.94733, 7.54369 51.94686, 7.543…
#> 7 13 14 <NA> footway (7.54012 51.94478, 7.539931 51.94514)
#> 8 8 10 <NA> path (7.53822 51.94546, 7.538131 51.94549, 7.538…
#> 9 7 15 <NA> track (7.540063 51.94468, 7.540338 51.94468, 7.54…
#> 10 16 17 <NA> track (7.5424 51.94599, 7.54205 51.94629, 7.54196…
#> # … with 841 more rows
Then plotting gets as easy as.
ggplot() +
geom_sf(data = st_as_sf(net, "edges")) +
geom_sf(data = st_as_sf(net, "nodes"))
The algorithms from igraph can be directly applied to the network.
head(igraph::edge_betweenness(net))
#> [1] 10406.362 12118.803 6837.847 4467.540 32124.052 674.000
igraph::is_connected(net)
#> [1] FALSE
Spatial filtering can be done with st_filter.
p1 = st_point(c(7.53173, 51.95662))
p2 = st_point(c(7.53173, 51.95190))
p3 = st_point(c(7.53778, 51.95190))
p4 = st_point(c(7.53778, 51.95662))
rect = st_multipoint(c(p1, p2, p3, p4)) %>%
st_cast('POLYGON') %>%
st_sfc(crs = 4326)
net_f = net %>%
st_filter(rect, .pred = st_intersects)
#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
par(mar = c(1, 1, 1, 1))
plot(net, col = "grey")
plot(rect, border = "Red", lwd = 2, add = TRUE)
plot(net_f, add = TRUE)
Created on 2020-06-16 by the reprex package (v0.3.0)
from sfnetworks.
Related Issues (20)
- Include `direction` as an argument to `st_network_cost()` HOT 4
- Installation Fail On MacOS HOT 2
- Unable to install HOT 10
- New st_precision method HOT 3
- Weird behaviour of to_spatial_subdivision with duplicated internal points HOT 2
- A new rounding_coords() function
- A few GEOS functions that could enhance sfnetworks
- Add an `active = NULL` argument to st_coordinates.sfnetwork HOT 1
- Adopt a more explicit error message when running edge_length (and related function) with active nodes HOT 1
- The print methods should return x invisibly HOT 1
- Converting igraph -> sfnetwork removes the linestring geometry from edges table HOT 3
- Outdated HTML snippet in roxygen generated Rd files HOT 3
- A slightly different approach for plot.sfnetwork HOT 2
- Package archived on CRAN HOT 1
- Test fails with the development version of igraph HOT 2
- Network cleaning: to_spatial_contracted returns mapply error HOT 4
- Converting sf_linestrings to sfnetwork causes some intersections to shift HOT 1
- Calculating Driving Distances using sfnetworks HOT 1
- Extracting GPS coordinates from SF network build from OSM Data, provides those in a wrong order HOT 8
- If the grouping variable is out of order, `to_spatial_contracted` returns incorrect node geometries HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sfnetworks.