-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_R_to_Python.R
More file actions
86 lines (75 loc) · 2.79 KB
/
data_R_to_Python.R
File metadata and controls
86 lines (75 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# ==== Exporting Files ====
# libraries
library(sf)
library(dplyr)
library(sfnetworks)
library(igraph)
library(tidygraph)
## Core Data -- to be saved within the "script" folder of the JDH article repo
# ACTION NEEDED: EDIT the following path according to YOUR docker location
setwd("C:/Users/aisro/Downloads/JDH_SpatialEquity/work")
### Buildings
st_write(buildings, "script/buildings.gpkg", delete_dsn = FALSE)
## Municipal Boundaries
st_write(aarhus, "script/aarhus_mun.geojson", delete_dsn = FALSE)
st_write(aarhus_city1952, "script/aarhus_city1952.gpkg", delete_dsn = FALSE)
## Combined Shelter Dataset
st_write(shelters, "script/shelters.gpkg", delete_dsn = FALSE)
### DMA
write.csv(dma, "script/dma.csv", row.names = FALSE)
# ### DEFUNCT: Network --- REPLACE WITH DMA
#
# #### Get nodes data
# nodes_geom <- vertex_attr(network, "geometry")
# nodes_index <- vertex_attr(network, ".tidygraph_node_index")
#
# #### Create nodes sf object
# network_nodes <- data.frame(.tidygraph_node_index = nodes_index) %>%
# st_sf(geometry = nodes_geom)
#
# #### Get edges data
# edges_geom <- edge_attr(network, "geometry")
# edges_index <- edge_attr(network, ".tidygraph_edge_index")
#
# # # Check all available attributes (if needed)
# # edge_attr_names(network)
# # vertex_attr_names(network)
#
# #### Get a few key edge attributes (remove/add more as needed)
# edges_osm_id <- edge_attr(network, "osm_id")
# edges_highway <- edge_attr(network, "highway")
# edges_name <- edge_attr(network, "name")
# edges_distance <- edge_attr(network, "distance_m")
#
# #### Create edges sf object
# network_edges <- data.frame(
# .tidygraph_edge_index = edges_index,
# osm_id = edges_osm_id,
# highway = edges_highway,
# name = edges_name,
# distance_m = edges_distance
# ) %>%
# st_sf(geometry = edges_geom)
#
# #### Export: nodes + edges
# st_write(network_nodes, "script/network_nodes.geojson", delete_dsn = FALSE)
# st_write(network_edges, "script/network_edges.geojson", delete_dsn = FALSE)
#
# #### Export: connectivity data
# edge_list <- as_data_frame(network, what = "edges")
# node_list <- as_data_frame(network, what = "vertices")
#
# write.csv(edge_list, "script/network_connectivity_edges.csv", row.names = FALSE)
# write.csv(node_list, "script/network_connectivity_nodes.csv", row.names = FALSE)
#
# print("Network data exported successfully!")
## DEFUNCT: Building-Shelter Pair Data
# building_shelter_pairs_csv <- building_shelter_pairs %>%
# st_drop_geometry() # issues occur without dropping geometry here (it is re-merged in Python)
#
# write.csv(building_shelter_pairs_csv, "script/building_shelter_pairs.csv", row.names = FALSE)
#
# buildings_spatial <- building_shelter_pairs %>%
# select(id_lokalId, byg404Koordinat)
#
# st_write(buildings_spatial, "script/buildings_from_pairs.gpkg", delete_dsn = FALSE)