-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path2_process.R
82 lines (69 loc) · 2.31 KB
/
2_process.R
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
# Steps for converting spatial features (sf) objects into SVG land
source("2_process/src/sf_to_coords.R")
source("2_process/src/coords_to_svg_path.R")
p2_targets <- list(
tar_target(svg_width, 1000),
tar_target(p2_view_bbox, st_bbox(p1_conus_states_sf)),
# Prepare CONUS states for SVG
tar_target(
p2_conus_states_names,
p1_conus_states_sf %>%
st_drop_geometry() %>%
pull(ID)
),
tar_target(
p2_conus_states_coords,
p1_conus_states_sf %>%
filter(ID %in% p2_conus_states_names) %>%
sf_to_coords(svg_width, view_bbox = p2_view_bbox),
pattern = map(p2_conus_states_names)
),
tar_target(
p2_conus_states_paths,
coords_to_svg_path(p2_conus_states_coords, close_path = TRUE),
pattern = map(p2_conus_states_coords)
),
# Prepare HUCs for SVG
tar_target(
p2_huc8s_coords,
sf_to_coords(p1_huc8s_sf[[1]], svg_width, view_bbox = p2_view_bbox),
pattern = map(p1_huc8s_sf),
# Keep HUCs in list format so that they can be given unique
# ids when they are added to the SVG
iteration = "list"
),
tar_target(
# This will create a vector with one string per polygon
p2_huc8s_paths,
coords_to_svg_path(p2_huc8s_coords, close_path = TRUE),
pattern = map(p2_huc8s_coords)
),
# Prepare rivers for SVG
# TODO: FIX THIS ISSUE
# Keep getting an error about "could not load dependencies of target
# p2_river_coords. Input must be a vector, not a <sfc_LINESTRING> object.
# Doing this fixes that error, which I don't really understand
tar_target(
needs_a_solution,
bind_rows(p1_rivers_sf)
),
tar_target(
# Returns a list so that each river can be a separate SVG path
p2_river_coords,
sf_to_coords_by_id(needs_a_solution,
id_col = "comid",
svg_width,
view_bbox = p2_view_bbox),
),
tar_target(
# This will create a vector with one string per river/comid
# Using coords_to_svg_path() but with `purrr::map()` bc we
# don't need to branch, just need to keep the resulting SVG
# paths separate for each river reach. Really fast, so its
# ok if we rebuild every time new rivers are added.
p2_river_paths,
p2_river_coords %>%
map(coords_to_svg_path, close_path = FALSE) %>%
unlist()
)
)