/
preprocess.yaml
154 lines (120 loc) · 6.9 KB
/
preprocess.yaml
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
target_default: preprocess
packages:
- vizlab
- rgdal
- dplyr
- tibble
- sbtools
- maptools
- geojsonio
- lwgeom
- sf
sources:
- scripts/preprocess/fetch_url.R
- scripts/preprocess/process_zip_to_shp.R
- scripts/preprocess/process_dictionaries.R
- scripts/preprocess/process_counties.R
- scripts/preprocess/process_counties_to_states.R
- scripts/preprocess/process_compute_centroids.R
- scripts/preprocess/push_SB_object.R
targets:
# --- fetch --- #
# See https://www.census.gov/geo/maps-data/data/cbf/cbf_counties.html for details on this file.
# this file includes counties for places we don't need:
# Northern Mariana Island (STATEFP=='69'), Guam (STATEFP=='66'), and American Samoa (STATEFP=='60')
# and also the places we do want:
# Virgin Islands, Puerto Rico, and all 50 states
# Note that because we're fetching here rather than vizlab, and with a simple function,
# there will be no automatic updates if the contents of the Census Bureau's file change.
# If they do (unlikely), you should delete your local copy of the file and build again.
cache/pre_county_boundaries_census.zip:
command: fetch_url(target_name, I('http://www2.census.gov/geo/tiger/GENZ2015/shp/cb_2015_us_county_500k.zip'))
# ^ very similar command is still in viz.yaml. we can take it out of there once we're computing
# county and state dictionaries in this preprocessing phase, but for now we need the same file both places.
# --- process --- #
county_boundaries_census_sp:
command: read_shp_zip('cache/pre_county_boundaries_census.zip')
county_boundaries_shifted_sp:
command: scale_shifted_shps(county_boundaries_census_sp, STATEFP = I(c('72','78','02')), scale = I(c(3, 3, 1/2)))
cache/pre_county_dictionary.json:
command: process_county_dictionary(target_name, county_boundaries_shifted_sp)
cache/pre_state_dictionary.json:
command: process_state_dictionary(target_name, county_boundaries_shifted_sp)
# --- simplication of counties --- #
# simplify closer to 1e-1 and quantize closer to 1e1 make smaller files
cache/pre_simpled_county_boundaries_USA.json:
command: process_counties(
outfile=target_name, county_sp=county_boundaries_shifted_sp,
simplify=I(1e-6), quantize=I(1e6),
county_dict_file='cache/pre_county_dictionary.json', script_file='scripts/preprocess/process_counties.sh')
# simplify somewhere between USA and zoom top optimize for mobile
cache/pre_simpled_county_boundaries_mobile.json:
command: process_counties(
outfile=target_name, county_sp=county_boundaries_shifted_sp,
simplify=I(5e-7), quantize=I(5e6),
county_dict_file='cache/pre_county_dictionary.json', script_file='scripts/preprocess/process_counties.sh')
# simplify closer to 1e-20 and quantize closer to 1e20 make higher resolution boundaries (bigger files)
cache/pre_simpled_county_boundaries_zoom.json:
command: process_counties(
outfile=target_name, county_sp=county_boundaries_shifted_sp,
simplify=I(1e-8), quantize=I(1e8),
county_dict_file='cache/pre_county_dictionary.json', script_file='scripts/preprocess/process_counties.sh')
# --- shift back scales after simplication of counties --- #
cache/pre_county_boundaries_USA.json:
command: rescale_write_shps(
target_name, "cache/pre_simpled_county_boundaries_USA.json", STATEFP = I(c('72','78','02')), scale = I(c(1/3, 1/3, 2)), quantize=I(1e6))
cache/pre_county_boundaries_mobile.json:
command: rescale_write_shps(
target_name, "cache/pre_simpled_county_boundaries_mobile.json", STATEFP = I(c('72','78','02')), scale = I(c(1/3, 1/3, 2)), coerce_dropped = I(TRUE), quantize=I(1e7))
cache/pre_county_boundaries_zoom.json:
command: rescale_write_shps(
target_name, "cache/pre_simpled_county_boundaries_zoom.json", STATEFP = I(c('72','78','02')), scale = I(c(1/3, 1/3, 2)), coerce_dropped = I(TRUE), quantize=I(1e8))
# --- use topojson versions of counties to create state boundaries --- #
cache/pre_state_boundaries_USA.json:
depends: scripts/preprocess/custom_projection.js
command: process_counties_to_states(
outfile=target_name, objects=I('states'), quantize=I(1e6), zoom_dims=I(FALSE),
county_topojson='cache/pre_county_boundaries_USA.json',
state_dict_file='cache/pre_state_dictionary.json', script_file = 'scripts/preprocess/process_counties_to_states.js')
cache/pre_state_boundaries_mobile.json:
depends: scripts/preprocess/custom_projection.js
command: process_counties_to_states(
outfile=target_name, objects=I('states'), quantize=I(5e6), zoom_dims=I(TRUE),
county_topojson='cache/pre_county_boundaries_mobile.json',
state_dict_file='cache/pre_state_dictionary.json', script_file = 'scripts/preprocess/process_counties_to_states.js')
cache/pre_state_boundaries_zoom.json:
depends: scripts/preprocess/custom_projection.js
command: process_counties_to_states(
outfile=target_name, objects=I('states'), quantize=I(1e8), zoom_dims=I(TRUE),
county_topojson='cache/pre_county_boundaries_zoom.json',
state_dict_file='cache/pre_state_dictionary.json', script_file = 'scripts/preprocess/process_counties_to_states.js')
# --- create county centroids from original sp object --- #
cache/pre_county_centroids_USA.json:
command: process_compute_centroids(
outfile=target_name, spdat=county_boundaries_census_sp,
county_dict_file='cache/pre_county_dictionary.json')
# --- publish --- #
SB_county_boundaries_USA_json:
command: push_SB_object(I("5ab154b1e4b081f61ab26420"), "cache/pre_county_boundaries_USA.json", I("county_boundaries_USA.json"))
SB_county_boundaries_mobile_json:
command: push_SB_object(I("5ab154b1e4b081f61ab26420"), "cache/pre_county_boundaries_mobile.json", I("county_boundaries_mobile.json"))
SB_county_boundaries_zoom_json:
command: push_SB_object(I("5ab154b1e4b081f61ab26420"), "cache/pre_county_boundaries_zoom.json", I("county_boundaries_zoom.json"))
SB_state_boundaries_USA_json:
command: push_SB_object(I("5ab154b1e4b081f61ab26420"), "cache/pre_state_boundaries_USA.json", I("state_boundaries_USA.json"))
SB_state_boundaries_mobile_json:
command: push_SB_object(I("5ab154b1e4b081f61ab26420"), "cache/pre_state_boundaries_mobile.json", I("state_boundaries_mobile.json"))
SB_state_boundaries_zoom_json:
command: push_SB_object(I("5ab154b1e4b081f61ab26420"), "cache/pre_state_boundaries_zoom.json", I("state_boundaries_zoom.json"))
SB_county_centroids_json:
command: push_SB_object(I("5ab154b1e4b081f61ab26420"), "cache/pre_county_centroids_USA.json", I("county_centroids_USA.json"))
# --- final --- #
preprocess:
depends:
- SB_county_boundaries_USA_json
- SB_county_boundaries_mobile_json
- SB_county_boundaries_zoom_json
- SB_state_boundaries_USA_json
- SB_state_boundaries_mobile_json
- SB_state_boundaries_zoom_json
- SB_county_centroids_json