-
Notifications
You must be signed in to change notification settings - Fork 9
/
prepublish.sh
executable file
·186 lines (156 loc) · 7.57 KB
/
prepublish.sh
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/bash
set -e
rm -rvf *-10t.json base.json
mkdir -p build
# Crawl the data pages for the download links
# Village URL
villageShpUrl=$(curl -Ls https://data.gov.tw/dataset/7438 | \
# Find the link that has the SHP tag
grep -io '"SHP","contentUrl":[^}]*"}' | \
# get the href tag
sed -E 's/.*contentUrl":"([^"]+).*/\1/g')
# Town URL
townShpUrl=$(curl -Ls https://data.gov.tw/dataset/7441 | \
# Find the link that has the SHP tag
grep -io '"SHP","contentUrl":[^}]*"}' | \
# get the href tag
sed -E 's/.*contentUrl":"([^"]+).*/\1/g')
# County URL
countyShpUrl=$(curl -Ls https://data.gov.tw/dataset/7442 | \
# Find the link that has the SHP tag
grep -io '"SHP","contentUrl":[^}]*"}' | \
# get the href tag
sed -E 's/.*contentUrl":"([^"]+).*/\1/g')
# Download and extract the archives
if [ ! -f build/village.zip ]; then
curl -Lo build/village.zip "${villageShpUrl}"
unzip -od build build/village.zip
fi
# Download and extract the archives
if [ ! -f build/town.zip ]; then
curl -Lo build/town.zip "${townShpUrl}"
unzip -od build build/town.zip
fi
# Download and extract the archives
if [ ! -f build/county.zip ]; then
curl -Lo build/county.zip "${countyShpUrl}"
unzip -od build build/county.zip
fi
###############################################################################
# Generate topojson files
# Boundaries for everything we care about
bbox=117.663,21.577,122.0202,26.671
# Village file
geo2topo -q 1e10 -n villages=<( \
shp2json -n --encoding=UTF-8 build/VILLAGE*.shp \
| ndjson-filter '!!d.properties.VILLNAME') \
| topomerge towns=villages -k 'd.properties.TOWNCODE' \
| topomerge counties=towns -k 'd.properties.COUNTYCODE' \
| topomerge nation=counties \
| toposimplify -f -s 1e-10 \
| node ./properties.js \
> villages-10t.json
# Use mapshaper to remove extra slivers and islands outside of the boundaries.
mapshaper -i villages-10t.json -clip bbox=${bbox} -filter-slivers -o force format=topojson villages-10t.json
mapshaper -i villages-10t.json -clean target=* -o force format=topojson villages-10t.json
# Town file
geo2topo -q 1e10 -n towns=<( \
shp2json -n --encoding=UTF-8 build/TOWN*.shp \
| ndjson-filter '!!d.properties.TOWNNAME') \
| topomerge counties=towns -k 'd.properties.COUNTYCODE' \
| topomerge nation=counties \
| toposimplify -f -s 1e-10 \
| node ./properties.js \
> towns-10t.json
# Use mapshaper to remove extra slivers and islands outside of the boundaries.
mapshaper -i towns-10t.json -clip bbox=${bbox} -filter-slivers -o force format=topojson towns-10t.json
mapshaper -i towns-10t.json -clean target=* -o force format=topojson towns-10t.json
# County file
geo2topo -q 1e10 -n counties=<( \
shp2json -n --encoding=UTF-8 build/COUNTY*.shp \
| ndjson-filter '!!d.properties.COUNTYNAME') \
| topomerge nation=counties \
| toposimplify -f -s 1e-10 \
| node ./properties.js \
> counties-10t.json
# Use mapshaper to remove extra slivers and islands outside of the boundaries.
mapshaper -i counties-10t.json -clip bbox=${bbox} -filter-slivers -o force format=topojson counties-10t.json
mapshaper -i counties-10t.json -clean target=* -o force format=topojson counties-10t.json
# Use mapshaper to remove layers of detail we don't want for nation
mapshaper -i counties-10t.json -drop target=counties -o format=topojson target=* nation-10t.json
# District file
geo2topo -q 1e10 -n villages=<( \
shp2json -n --encoding=UTF-8 build/VILLAGE*.shp \
| ndjson-filter '!!d.properties.VILLNAME') \
| DISTRICTS="true" node ./properties.js \
| topomerge districts=villages -k 'd.properties.DISTRICTCODE' \
| topomerge counties=districts -k 'd.properties.COUNTYCODE' \
| topomerge nation=counties \
| toposimplify -f -s 1e-10 \
> districts-10t.json
# Use mapshaper to remove extra slivers and islands outside of the boundaries.
mapshaper -i districts-10t.json -clip bbox=${bbox} -filter-slivers -o force format=topojson districts-10t.json
mapshaper -i districts-10t.json -clean target=* -o force format=topojson districts-10t.json
# Use mapshaper to remove layers of detail we don't want for district
mapshaper -i districts-10t.json -drop target=villages -o force format=topojson target=* districts-10t.json
# Village mercator projections
geo2topo -q 1e7 -n \
villages=<(shp2json -n --encoding=UTF-8 build/VILLAGE*.shp \
| ndjson-filter '!!d.properties.VILLNAME' \
| geoproject --require mercatorTw='./mercatorTw.cjs' -n 'mercatorTw()') \
compBorders=<(node compBordersGeo.js) \
| topomerge towns=villages -k 'd.properties.TOWNCODE' \
| topomerge counties=towns -k 'd.properties.COUNTYCODE' \
| topomerge nation=counties \
| toposimplify -f -s 1e-6 \
| node ./properties.js \
> villages-mercator-10t.json
# Use mapshaper to remove extra slivers and islands outside of the boundaries.
mapshaper -i villages-mercator-10t.json -filter-slivers -o force format=topojson villages-mercator-10t.json
mapshaper -i villages-mercator-10t.json -clean target=* -o force format=topojson villages-mercator-10t.json
# Town mercator projections
geo2topo -q 1e7 -n \
towns=<(shp2json -n --encoding=UTF-8 build/TOWN*.shp \
| ndjson-filter '!!d.properties.TOWNNAME' \
| geoproject --require mercatorTw='./mercatorTw.cjs' -n 'mercatorTw()') \
compBorders=<(node compBordersGeo.js) \
| topomerge counties=towns -k 'd.properties.COUNTYCODE' \
| topomerge nation=counties \
| toposimplify -f -s 1e-6 \
| node ./properties.js \
> towns-mercator-10t.json
# Use mapshaper to remove extra slivers and islands outside of the boundaries.
mapshaper -i towns-mercator-10t.json -filter-slivers -o force format=topojson towns-mercator-10t.json
mapshaper -i towns-mercator-10t.json -clean target=* -o force format=topojson towns-mercator-10t.json
# County mercator projections
geo2topo -q 1e7 -n \
counties=<(shp2json -n --encoding=UTF-8 build/COUNTY*.shp \
| ndjson-filter '!!d.properties.COUNTYNAME' \
| geoproject --require mercatorTw='./mercatorTw.cjs' -n 'mercatorTw()') \
compBorders=<(node compBordersGeo.js) \
| topomerge nation=counties \
| toposimplify -f -s 1e-6 \
| node ./properties.js \
> counties-mercator-10t.json
# Use mapshaper to remove extra slivers and islands outside of the boundaries.
mapshaper -i counties-mercator-10t.json -filter-slivers -o force format=topojson counties-mercator-10t.json
mapshaper -i counties-mercator-10t.json -clean target=* -o force format=topojson counties-mercator-10t.json
# Use mapshaper to remove layers of detail we don't want for nation
mapshaper -i counties-mercator-10t.json -drop target=counties -o format=topojson target=* nation-mercator-10t.json
# District mercator projections
geo2topo -q 1e7 -n \
villages=<(shp2json -n --encoding=UTF-8 build/VILLAGE*.shp \
| ndjson-filter '!!d.properties.VILLNAME' \
| geoproject --require mercatorTw='./mercatorTw.cjs' -n 'mercatorTw()') \
compBorders=<(node compBordersGeo.js) \
| DISTRICTS="true" node ./properties.js \
| topomerge districts=villages -k 'd.properties.DISTRICTCODE' \
| topomerge counties=districts -k 'd.properties.COUNTYCODE' \
| topomerge nation=counties \
| toposimplify -f -s 1e-6 \
> districts-mercator-10t.json
# Use mapshaper to remove extra slivers and islands outside of the boundaries.
mapshaper -i districts-mercator-10t.json -filter-slivers -o force format=topojson districts-mercator-10t.json
mapshaper -i districts-mercator-10t.json -clean target=* -o force format=topojson districts-mercator-10t.json
# Use mapshaper to remove layers of detail we don't want for district
mapshaper -i districts-mercator-10t.json -drop target=villages -o force format=topojson target=* districts-mercator-10t.json