Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
bind neighborhoods to PGH graph
Browse files Browse the repository at this point in the history
  • Loading branch information
mdlincoln committed Feb 14, 2019
1 parent 8acc490 commit 7adb1fa
Show file tree
Hide file tree
Showing 4 changed files with 421,196 additions and 580,082 deletions.
59 changes: 8 additions & 51 deletions osmar/drake.R
Expand Up @@ -32,14 +32,19 @@ pgh_plan <- drake_plan(
pgh_nodes_sf = osm_nodes_to_sf(download_osm),
# Shapefile for PGH boundaries
pgh_boundary_layer = read_sf(file_in("osmar/input_data/Pittsburgh_River_Boundary")),
pgh_block_data_layer = read_sf(file_in("osmar/input_data/Neighborhoods_")),
in_bound_points = nodes_within_boundaries(pgh_nodes_sf, pgh_boundary_layer),
node_communities = st_join(pgh_nodes_sf, pgh_block_data_layer),
pgh_unlimited_graph = konigsberg_graph(src = download_osm, path_filter = automobile_highways, bridge_filter = main_bridges),
pgh_tidy_graph = filter_bridges_to_nodes(pgh_unlimited_graph, node_ids = in_bound_points),
pgh_filtered_graph = filter_bridges_to_nodes(pgh_unlimited_graph, node_ids = in_bound_points),
pgh_tidy_graph = pgh_filtered_graph %>%
activate(nodes) %>%
left_join(select(st_set_geometry(node_communities, NULL), id, neighborhood = hood) %>% distinct(id, .keep_all = TRUE), by = "id"),
pgh_edge_bundles = collect_edge_bundles(pgh_tidy_graph),
pgh_nodes = write_csv(
as_tibble(pgh_tidy_graph, "nodes") %>%
mutate(node_id = row_number()) %>%
select(id = node_id, osm_node_id = id, lat, lon, osm_label = label),
select(id = node_id, osm_node_id = id, lat, lon, osm_label = label, neighborhood),
path = file_out("osmar/output_data/pgh_nodes.csv"), na = ""),
pgh_edges = write_csv(
as_tibble(pgh_tidy_graph, "edges") %>%
Expand All @@ -53,42 +58,8 @@ pgh_plan <- drake_plan(
bridge_id, distance,
within_boundaries),
path = file_out("osmar/output_data/pgh_edges.csv"), na = ""),
pgh_bundles = write_lines(toJSON(pgh_edge_bundles, pretty = TRUE), path = "osmar/output_data/pgh_bundles.json")
)

# Locate pathways ----

# In order to determine which starting points need to be used, we need to build
# all pgh_plan targets UP TO THIS POINT in order to derive the correct
# pgh_starting_points values. From these values, we'll generate a new set of
# targets within pgh_expanded_pathways.

# pgh_pathway_plan_generic <- drake_plan(pgh_pathway = target(
# greedy_search(starting_point = sp__, graph = pgh_tidy_graph, edge_bundles = pgh_edge_bundles, distances = E(pgh_tidy_graph)$distance, quiet = TRUE),
# trigger = trigger(command = FALSE, depend = FALSE, file = FALSE)))
#
# pgh_expanded_pathways <- evaluate_plan(pgh_pathway_plan_generic, rules = list(sp__ = readd("pgh_starting_points")))
#
# # After building each pathway, run the assessment functions...
# assessment_plan_generic <- drake_plan(path_performance = glance(pathway = p__))
# assessment_plan <- evaluate_plan(assessment_plan_generic, rules = list(p__ = pgh_expanded_pathways$target))
# # ... and bind them into a dataframe
# pgh_performances <- gather_plan(assessment_plan, target = "pgh_performances", gather = "rbind")
#
# pgh_plan <- bind_plans(
# pgh_plan,
# pgh_expanded_pathways,
# assessment_plan,
# pgh_performances
# )
#
#

# At this point, it is necessary to run the pathways to evaluate which one we want to use for visualization purposes.
pgh_bundles = write_lines(toJSON(pgh_edge_bundles, pretty = TRUE), path = "osmar/output_data/pgh_bundles.json"),

# Visualize Pathways ----

plot_plan <- drake_plan(
test_run = greedy_search(pgh_tidy_graph, edge_bundles = pgh_edge_bundles, distances = E(pgh_tidy_graph)$distance, starting_point = 1),
path_result = write_lines(toJSON(test_run$epath, pretty = TRUE), path = file_out("osmar/output_data/paths/edge_steps.json")),
path_summary = write_csv(glance(test_run), na = "", path = file_out("osmar/output_data/paths/path_summary.csv")),
Expand Down Expand Up @@ -118,17 +89,3 @@ plot_plan <- drake_plan(
),
output_leaflet = mapshot(leaflet_map, url = file_out(fs::path(getwd(), "osmar/output_data/pgh_leaflet.html")))
)

# Produce several shapefiles
shp_plan <- drake_plan(
pathway_shp = write_sf(pathway_layer, file_out("osmar/output_data/shapefiles/pathway_linestring"), driver = "ESRI Shapefile"),
# pathway_multiline_shp = write_sf(pathway_multiline_layer, file_out("osmar/output_data/shapefiles/pathway_multilinestring"), driver = "ESRI Shapefile"),
bridge_shp = write_sf(bridges_layer, file_out("osmar/output_data/shapefiles/bridges_shp"), driver = "ESRI Shapefile"),
crossed_roads_shp = write_sf(crossed_roads_layer, file_out("osmar/output_data/shapefiles/pathway_shp"), driver = "ESRI Shapefile")
)

pgh_plan <- bind_plans(
pgh_plan,
shp_plan,
plot_plan
)

0 comments on commit 7adb1fa

Please sign in to comment.