Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

dodgr_insert_vertex

dodgr_insert_vertex


Description

Insert a new node or vertex into a network

Usage

dodgr_insert_vertex(graph, v1, v2, x = NULL, y = NULL)

Arguments

graph

A flat table of graph edges. Must contain columns labelled from and to, or start and stop. May also contain similarly labelled columns of spatial coordinates (for example from_x) or stop_lon).

v1

Vertex defining start of graph edge along which new vertex is to be inserted

v2

Vertex defining end of graph edge along which new vertex is to be inserted (order of v1 and v2 is not important).

x

The x-coordinate of new vertex. If not specified, vertex is created half-way between v1 and v2.

y

The y-coordinate of new vertex. If not specified, vertex is created half-way between v1 and v2.

Value

A modified graph with specified edge between defined start and end vertices split into two edges either side of new vertex.

See Also

Examples

graph <- weight_streetnet (hampi)
e1 <- sample (nrow (graph), 1)
v1 <- graph$from_id [e1]
v2 <- graph$to_id [e1]
# insert new vertex in the middle of that randomly-selected edge:
graph2 <- dodgr_insert_vertex (graph, v1, v2)
nrow (graph); nrow (graph2) # new edges added to graph2

dodgr

Distances on Directed Graphs

v0.2.11
GPL-3
Authors
Mark Padgham [aut, cre], Andreas Petutschnig [aut], Robin Lovelace [ctb], Andrew Smith [ctb], Malcolm Morgan [ctb], Shane Saunders [cph] (Original author of included code for priority heaps)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.