-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_map.bash
executable file
·291 lines (242 loc) · 8.1 KB
/
make_map.bash
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
#!/bin/bash
usage() {
echo ""
echo -e "-o \tSet .osm.pbf file"
echo -e "-c \tSet polyfile used to select region used instead of complete"
echo -e "-b \tLocation of pre-preocessed boundaries. Thus, boundary processing is omitted"
echo ""
echo -ne "usage:"
echo -e "\tcut polygon out of map and generate garmin image + png file:"
echo -e "\t$0 -c my.poly -o europe.osm.pbf"
echo ""
echo -e "\tgenerate garmin image out of complete map"
echo -e "\t$0 -o europe.osm.pbf"
echo ""
echo -e "\tgenerate png file from polygon only (fast)"
echo -e "\t$0 -c my.poly"
echo ""
}
##############################################################################
# save working directory, needed to find other stuff
##############################################################################
HOME=$PWD
##############################################################################
# set variables to tools binaries
##############################################################################
SPLITTER=$HOME/tools/splitter/splitter.jar
MKGMAP=$HOME/tools/mkgmap/mkgmap.jar
OSMOSIS=$HOME/tools/osmosis/bin/osmosis
OSMFILTER=$HOME/tools/osmfilter/osmfilter32
OSMCONVERT=$HOME/tools/osmconvert/osmconvert32
##############################################################################
# set maximum Java heap size (for mkgmap)
##############################################################################
MEM_USAGE=-Xmx4000m
##############################################################################
# define style and typ file locations
##############################################################################
#STYLE_FILE=$HOME/tools/teddy/teddy
TYP_FILE=$HOME/tools/teddy/teddy.TYP
FAMILY_ID=42
##############################################################################
# set variables to select build step; 0=false
# these variables are set using options during script call
##############################################################################
USE_BOUNDS=0 # needed to be independent of parameter order
DO_BOUNDS=0
DO_CUT=0
DO_SPLIT=0
DO_MKGMAP=0
DO_PNG=0
##############################################################################
# getopts
# -p png
# -c cut polygon out of map (implicit -p)
# -o osm.pbf file
##############################################################################
while getopts "c:o:b:" OPTION
do
case $OPTION in
c) # cut region using poly file
POLYFILE=$HOME/$OPTARG
echo "using $POLYFILE"
DO_CUT=1
DO_PNG=1
;;
o) # osm.pbf file
DO_BOUNDS=1
DO_SPLIT=1
DO_MKGMAP=1
OSM_PBF=$HOME/$OPTARG
echo "using $OSM_PBF"
;;
b) # use pre-processed bounds
USE_BOUNDS=1
#DO_BOUNDS=0
PREBOUNDS=$HOME/$OPTARG
echo "using $PREBOUNDS"
;;
# Unknown option. No need for an error, getopts informs
# the user itself.
\?) exit 1;;
esac
done
if [ $USE_BOUNDS = 1 ]; then
DO_BOUNDS=0
fi
if [ $# -ne 2 ] && [ $# -ne 4 ] && [ $# -ne 6 ]
then
usage
exit 1
fi
##############################################################################
# if no poly file selected, the input for splitter is the complete map
# otherwise, splitter uses the reduced map as input
##############################################################################
if [ $DO_CUT = 1 ]; then
INPUT_SPLITTER=$HOME/tmp/reduced_map/reduced.osm.pbf
else
INPUT_SPLITTER=$OSM_PBF
fi
##############################################################################
# if no osm.pbf file is given, but poly file and png,
# generate png out of poly (is fast) and omit cutting
##############################################################################
if [ $DO_MKGMAP = 0 ]; then
DO_CUT=0
fi
##############################################################################
# generate tmp directory for processing stuff
# delete old contents
##############################################################################
mkdir -p tmp
pushd tmp
rm -rf bounds
rm -rf png
rm -rf reduced_map
rm -rf splitter
##############################################################################
# pre-process bounds, necessary for address search index
# could also be done with pbf after osmosis to save time
##############################################################################
if [ $DO_BOUNDS = 1 ]; then
echo "Pre-process boundaries"
PREBOUNDS=$HOME/tmp/bounds/temp_bounds
mkdir -p bounds
pushd bounds
$OSMCONVERT $OSM_PBF --out-o5m >temp.o5m
$OSMFILTER temp.o5m --keep-nodes= \
--keep-ways-relations="boundary=administrative =postal_code postal_code=" \
--out-o5m > temp-boundaries.o5m
java $MEM_USAGE -cp $MKGMAP \
uk.me.parabola.mkgmap.reader.osm.boundary.BoundaryPreprocessor \
temp-boundaries.o5m \
temp_bounds
popd
fi
##############################################################################
# cut selected polygon out of bigger map
##############################################################################
if [ $DO_CUT = 1 ]; then
echo "Cutting polygon out of map"
mkdir -p reduced_map
pushd reduced_map
$OSMOSIS --read-pbf $OSM_PBF --bounding-polygon file=$POLYFILE --write-pbf reduced.osm.pbf omitmetadata=true
popd
fi
##############################################################################
# split tiles so that mkgmap can process it
##############################################################################
if [ $DO_SPLIT = 1 ]; then
echo "Start splitter"
mkdir -p splitter
pushd splitter
java $MEM_USAGE -jar $SPLITTER --cache=./tmp --output=xml --max-nodes=800000 $INPUT_SPLITTER
popd
fi
##############################################################################
# mkgmap
##############################################################################
# Teddy:
# --location-autofill=is_in,nearest
# --bounds not used!!
# me:
# --bounds=/home/nico/Development/osm/bounds_20130420 (add only this works also)
# --location-autofill=bounds (add this, no change??)
#/home/nico/Development/osm/own_stuff/boundary/local/
#/home/nico/Development/osm/bounds_20130420
#--style-file=$STYLE_FILE \
if [ $DO_MKGMAP = 1 ]; then
java $MEM_USAGE -jar $MKGMAP \
--keep-going \
--family-id=$FAMILY_ID \
--reduce-point-density=4 \
--merge-lines \
--generate-sea=multipolygon,extend-sea-sectors,close-gaps=6000,floodblocker \
--bounds=$PREBOUNDS \
--housenumbers \
--location-autofill=bounds,is_in,nearest \
--add-pois-to-areas \
--remove-short-arcs \
--country-name=GERMANY \
--country-abbr=GER \
--family-name="OSM Map" \
--description="OSM Map from NiF - "`date +%F` \
--area-name=DACH \
--gmapsupp \
--tdbfile \
--latin1 \
--net \
--style=default \
--route \
--index \
--name-tag-list='name:de,name,name:latin,name:en' \
splitter/*.osm.gz $TYP_FILE
fi
##############################################################################
# make png to check polygon
##############################################################################
if [ $DO_PNG = 1 ]; then
mkdir -p png
pushd png
perl $HOME/tools/osm-extract/polygons/polyconvert.pl $POLYFILE > temp.gpx
perl $HOME/tools/gpx2png/gpx2png.pl temp.gpx
popd
fi
##############################################################################
# leaving tmp directory
##############################################################################
popd
##############################################################################
# copy output
# therefore, generate subfolder in output with current date+time
# a text file will be added (00_info.txt) to provide information about
# how this script was called
##############################################################################
mkdir -p output
pushd output
OUTPUT_DIR=$(date +%Y%m%d_%H%M%S)
mkdir $OUTPUT_DIR
pushd $OUTPUT_DIR
echo "These output files were generated with the following parameters:" > 00_info.txt
echo "" >> 00_info.txt
if [ $DO_PNG = 1 ]; then
mv $HOME/tmp/png/map.png .
echo "polyfile: "$POLYFILE >> 00_info.txt
fi
if [ $DO_MKGMAP = 1 ]; then
mv $HOME/tmp/gmapsupp.img .
if [ $DO_BOUNDS = 0 ]; then
echo "pre-processed boundaries: "$PREBOUNDS >> 00_info.txt
fi
mkdir tdb
pushd tdb
find $HOME/tmp/ -maxdepth 1 -type f -exec mv {} . \;
popd
echo "osm_pbf: "$OSM_PBF >> 00_info.txt
fi
popd
##############################################################################
# finished :-)
##############################################################################
echo "finished"