Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spatial map of vertices measures #402

Open
agila5 opened this issue May 19, 2020 · 1 comment
Open

Spatial map of vertices measures #402

agila5 opened this issue May 19, 2020 · 1 comment

Comments

@agila5
Copy link
Collaborator

agila5 commented May 19, 2020

Problem

At the moment there is no easy and automatic way to represent network measures estimated for the vertices.

Solution

The algorithm behind SpatialLinesNetwork() defines two attributes for the igraph object named x and y that represent the coordinates of the vertices:

g <- igraph::graph(gdata$pts0, directed = FALSE)
nodes <- s[gdata$upts + 1, ]
g$x <- nodes[, 1] # x-coordinate vertex
g$y <- nodes[, 2] # y-coordinate vertex
g$n <- as.vector(table(gdata$pts0)) # nr of edges

We can use these coordinates to create an sf object of POINTS and add/plot igraph measures related to vertices. For example:

# packages
library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(stplanr)
library(igraph)
library(tmap)

# data
route_network_sf <- rnet_breakup_vertices(route_network_sf)
sln_sf <- SpatialLinesNetwork(route_network_sf)

# Estimate vertices measures
sln_vertices_strength <- strength(sln_sf@g)

# Rebuild the sf object
sln_vertices <- st_as_sf(
  data.frame(
    x = sln_sf@g$x, 
    y = sln_sf@g$y, 
    strength = sln_vertices_strength
  ), 
  coords = c("x", "y"), 
  crs = 4326
)

# Map
tm_shape(sln_sf@sl) + 
  tm_lines() + 
tm_shape(sln_vertices) + 
  tm_dots(size = "strength")

Created on 2020-05-19 by the reprex package (v0.3.0)

IMO the next step is to 1) document this "feature" or 2) create a new function to automatise this process.

@Robinlovelace
Copy link
Member

👍 I think that will greatly improve the usefulness of the class for relatively little new code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants