-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·341 lines (321 loc) · 8.29 KB
/
build.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# prerequisite: install postgresql, postgis, osm2pgsql (on Mac OS X take a look at https://github.com/OSGeo/homebrew-osgeo4mac)
# basics: wget and unzip
CENTRE="[-4.0, 54.1]"
# Pick a Geofabrik download. Choices reflect what https://download.geofabrik.de/europe/great-britain.html offers
PS3='Please enter your choice: '
options=(
"uk"
"england"
"scotland"
"wales"
"bedfordshire"
"berkshire"
"bristol"
"buckinghamshire"
"cambridgeshire"
"cheshire"
"cornwall"
"cumbria"
"derbyshire"
"devon"
"dorset"
"durham"
"east-sussex"
"east-yorkshire-with-hull"
"essex"
"gloucestershire"
"greater-london"
"greater-manchester"
"hampshire"
"herefordshire"
"hertfordshire"
"isle-of-wight"
"kent"
"lancashire"
"leicestershire"
"lincolnshire"
"merseyside"
"norfolk"
"north-yorkshire"
"northamptonshire"
"northumberland"
"nottinghamshire"
"oxfordshire"
"rutland"
"shropshire"
"somerset"
"south-yorkshire"
"staffordshire"
"suffolk"
"surrey"
"tyne-and-wear"
"warwickshire"
"west-midlands"
"west-sussex"
"west-yorkshire"
"wiltshire"
"worcestershire"
)
select opt in "${options[@]}"
do
AREA=$opt
case $opt in
"uk")
;;
"england")
CENTRE="[-1.48, 52.36]"
;;
"scotland")
CENTRE="[-3.95, 56.13]"
;;
"wales")
CENTRE="[-3.68, 52.30]"
;;
"bedfordshire")
CENTRE="[-0.67, 52.11]"
;;
"berkshire")
CENTRE="[-1.06, 51.37]"
;;
"bristol")
CENTRE="[-2.58, 51.45]"
;;
"buckinghamshire")
CENTRE="[-0.81, 51.78]"
;;
"cambridgeshire")
CENTRE="[0.05. 52.32]"
;;
"cheshire")
CENTRE="[-2.81, 53.30]"
;;
"cornwall")
CENTRE="[-4.83, 50.42]"
;;
"cumbria")
CENTRE="[-2.89, 54.57]"
;;
"derbyshire")
CENTRE="[-1.57, 53.09]"
;;
"devon")
CENTRE="[-3.80, 50.73]"
;;
"dorset")
CENTRE="[-2.33, 50.82]"
;;
"durham")
CENTRE="[-1.58, 54.77]"
;;
"east-sussex")
CENTRE="[0.31, 50.92]"
;;
"east-yorkshire-with-hull")
CENTRE="[-0.43, 53.88]"
;;
"essex")
CENTRE="[0.55, 51.77]"
;;
"gloucestershire")
CENTRE="[-2.13, 51.80]"
;;
"greater-london")
CENTRE="[-0.10, 51.49]"
;;
"greater-manchester")
CENTRE="[-2.33, 53.51]"
;;
"hampshire")
CENTRE="[-1.34, 51.04]"
;;
"herefordshire")
CENTRE="[-2.78, 52.10]"
;;
"hertfordshire")
CENTRE="[-0.22, 51.80]"
;;
"isle-of-wight")
CENTRE="[-1.31, 50.67]"
;;
"kent")
CENTRE="[0.78, 51.17]"
;;
"lancashire")
CENTRE="[-2.62, 53.82]"
;;
"leicestershire")
CENTRE="[-1.13, 52.66]"
;;
"lincolnshire")
CENTRE="[-0.22, 53.08]"
;;
"merseyside")
CENTRE="[-2.91, 53.42]"
;;
"norfolk")
CENTRE="[0.91, 52.66]"
;;
"north-yorkshire")
CENTRE="[-1.50, 54.20]"
;;
"northamptonshire")
CENTRE="[-0.90, 52.28]"
;;
"northumberland")
CENTRE="[-2.09, 55.26]"
;;
"nottinghamshire")
CENTRE="[-0.98, 53.12]"
;;
"oxfordshire")
CENTRE="[-1.31, 51.75]"
;;
"rutland")
CENTRE="[-0.64, 52.64]"
;;
"shropshire")
CENTRE="[-2.69, 52.66]"
;;
"somerset")
CENTRE="[-3.06, 51.09]"
;;
"south-yorkshire")
CENTRE="[-1.34, 53.48]"
;;
"staffordshire")
CENTRE="[-2.04, 52.80]"
;;
"suffolk")
CENTRE="[1.07, 52.16]"
;;
"surrey")
CENTRE="[-0.42, 51.24]"
;;
"tyne-and-wear")
CENTRE="[-1.57, 54.95]"
;;
"warwickshire")
CENTRE="[-1.56, 52.28]"
;;
"west-midlands")
CENTRE="[-1.95, 52.48]"
;;
"west-sussex")
CENTRE="[-1.5, 50.7]"
;;
"west-yorkshire")
CENTRE="[-1.73, 53.73]"
;;
"wiltshire")
CENTRE="[-1.94, 51.27]"
;;
"worcestershire")
CENTRE="[-2.14, 52.19]"
;;
esac
break
done
DBNAME="osm-${AREA}"
psql -c "create role osmuk_user LOGIN PASSWORD 'osmuk';"
createdb $DBNAME -O osmuk_user
psql -d $DBNAME -c "create extension if not exists postgis;"
psql -d $DBNAME -c "create extension if not exists hstore;"
if [ ! -f openstreetmap-carto-master/openstreetmap-carto.style ]; then
wget https://github.com/gravitystorm/openstreetmap-carto/archive/master.zip
unzip master.zip
rm master.zip
fi
if [ $AREA == "uk" ]; then
ROOT="europe/"
EXTRACT="britain-and-ireland"
elif [ $AREA == "england" ] || [ $AREA == "scotland" ] || [ $AREA == "wales" ]; then
ROOT="europe/great-britain/"
EXTRACT=$AREA
elif [ $AREA != "uk" ]; then
ROOT="europe/great-britain/england/"
EXTRACT=$AREA
fi
wget "http://download.geofabrik.de/${ROOT}${EXTRACT}-latest.osm.pbf"
osm2pgsql \
--create \
--slim \
--cache 1000 \
--number-processes 2 \
--hstore-all \
--multi-geometry \
--style openstreetmap-carto-master/openstreetmap-carto.style \
--tag-transform-script openstreetmap-carto-master/openstreetmap-carto.lua \
--database $DBNAME "${EXTRACT}-latest.osm.pbf"
# Some indexes to speed things up
psql -d $DBNAME -c "CREATE INDEX planet_osm_point_amenity
ON public.planet_osm_point USING btree
(amenity ASC NULLS LAST)
INCLUDE(amenity)
TABLESPACE pg_default;"
psql -d $DBNAME -c "CREATE INDEX planet_osm_point_shop
ON public.planet_osm_point USING btree
(shop ASC NULLS LAST)
TABLESPACE pg_default;"
psql -d $DBNAME -c "CREATE INDEX planet_osm_polygon_amenity
ON public.planet_osm_polygon USING btree
(amenity ASC NULLS LAST)
TABLESPACE pg_default;"
psql -d $DBNAME -c "CREATE INDEX planet_osm_polygon_shop
ON public.planet_osm_polygon USING btree
(shop ASC NULLS LAST)
TABLESPACE pg_default;"
psql -d $DBNAME -c "CREATE INDEX planet_osm_point_name
ON public.planet_osm_point USING btree
(name text_pattern_ops ASC NULLS LAST)
TABLESPACE pg_default;"
psql -d $DBNAME -c "CREATE INDEX planet_osm_polygon_name
ON public.planet_osm_polygon USING btree
(name text_pattern_ops ASC NULLS LAST)
TABLESPACE pg_default;"
psql -d $DBNAME -c "CREATE INDEX planet_osm_point_geom
ON public.planet_osm_point USING gist
(way)
TABLESPACE pg_default;"
psql -d $DBNAME -c "CREATE INDEX planet_osm_polygon_geom
ON public.planet_osm_polygon USING gist
(way)
TABLESPACE pg_default;"
# SQL to remove Eire
psql -d $DBNAME -c "
DELETE
FROM public.planet_osm_point
WHERE osm_id in
(
SELECT osm.osm_id
FROM public.planet_osm_point osm
JOIN public.planet_osm_polygon eire on eire.osm_id='-62273'
WHERE st_within(osm.way, eire.way)
);
"
psql -d $DBNAME -c "
DELETE
FROM public.planet_osm_polygon
WHERE osm_id in
(
SELECT osm.osm_id
FROM public.planet_osm_polygon osm
JOIN public.planet_osm_polygon eire on eire.osm_id='-62273'
WHERE st_within(osm.way, eire.way)
);
"
psql -d $DBNAME -c "
DELETE
FROM public.planet_osm_roads
WHERE osm_id in
(
SELECT osm.osm_id
FROM public.planet_osm_polygon osm
JOIN public.planet_osm_polygon eire on eire.osm_id='-62273'
WHERE st_within(osm.way, eire.way)
);
"
## configure and run vector tile server
psql -d $DBNAME -c "grant select on all tables in schema public to osmuk_user;"
sed -iE "s/'database': 'osm-[a-z/-]*'/'database': '${DBNAME}'/g" minimal-mvt.py
sed -iE "s/'center': .*$/'center': ${CENTRE},/g" map-mapboxgl/index.html
python3 minimal-mvt.py