| ox_union | R Documentation |
osm_graph objectsCombines two or more graphs into a single osm_graph. Node
and edge tables are stacked; nodes sharing an osmid are merged (the first
occurrence wins) and edges duplicated across graphs are dropped. Attribute
columns present in one graph but not another are filled with NA.
ox_union(..., dedupe_edges = TRUE)
... |
Two or more |
dedupe_edges |
Drop edges that appear in more than one graph with
identical |
Nodes with the same osmid are treated as the same location, which is what
stitches the graphs together: overlapping downloads share their OSM node
ids, and a hand-built network (say, a metro layer) connects to a street
graph wherever its edges reference street-node osmids. Custom networks
should therefore use node ids that do not collide with OSM's except where a
connection is intended (negative ids are a safe choice).
An osm_graph. meta$network_type concatenates the
distinct input types (e.g. "drive+walk"), meta$simplified is TRUE
only if every input was simplified, and meta$union_of records how many
graphs were combined.
g1 <- example_osm_graph(n = 3)
# a second, disjoint network with its own node ids
g2 <- example_osm_graph(n = 3)
g2$nodes$osmid <- g2$nodes$osmid + 1000
g2$edges$u <- g2$edges$u + 1000
g2$edges$v <- g2$edges$v + 1000
u <- ox_union(g1, g2)
u
# unioning overlapping graphs dedupes shared nodes and edges
nrow(ox_union(g1, g1)$edges) == nrow(g1$edges)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.