Created
November 1, 2017 09:23
-
-
Save mdsumner/4470d11343739d36950275ec71d68fd2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(silicate) | |
data("wrld_simpl", package = "maptools") | |
#edges are unique segments (undirected) | |
#segments are directed instances of edges, belonging to arcs/ways or feature boundaries | |
library(silicate) | |
library(sf) | |
x <- PATH(st_as_sf(wrld_simpl)) | |
#x <- PATH(minimal_mesh) | |
arcs <- sc_arc(x) | |
## we now need a generic PATH constructor | |
## we have unique vertices | |
xarc <- x | |
xarc$path_link_vertex <- transmute(arcs, vertex_, path_ = arc_) | |
xarc$path <- distinct(xarc$path_link_vertex, path_) %>% | |
mutate(object_ = path_) | |
xarc$object <- tibble(object_ = xarc$path$object_) | |
## now we want segments, so we have the path_identifier | |
## (the segments are already normalized in arc form) | |
edges <- sc_segment(xarc) | |
from <- edges %>% transmute(vertex_ = .vertex0) %>% | |
inner_join(x[["vertex"]]) %>% | |
transmute(xfr = x_, yfr = y_) | |
to <- edges %>% transmute(vertex_ = .vertex1, path_) %>% | |
inner_join(x[["vertex"]]) %>% | |
transmute(xto = x_, yto = y_, col = stringr::str_sub(viridis::viridis(nrow(xarc$path))[factor(path_)], 1, 7), lwd = 0.5) | |
scale <- 4 | |
offset <- 180 | |
svgplot_lines(bind_cols(from, to) %>% mutate(xfr = offset + xfr * scale, | |
yfr = offset + yfr * scale, | |
xto = offset + xto * scale, | |
yto = offset + yto * scale), "b.html") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment