aboutsummaryrefslogtreecommitdiffstats
path: root/osm/download_and_convert.sh
blob: d5c4d5a1714aa8d356360fce49831a4dabbca975 (plain)
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
#!/bin/bash
#set -x

if [ $# -ne 8 ]
then
   echo "wrong argument count"
   exit 1
fi

url_map="$1"
url_map_filename="$(basename $url_map)"
download_map="$dir_maps/$url_map_filename"
url_poly="$2"
url_poly_filename="$(basename $url_poly)"
download_poly="$dir_poly/$url_poly_filename"
mapfile="$3"
wm_type="$4"
start_zoom="$5"
language="$6"
use_poly="$7"
output_subdir="$8"
stage_map="$dir_stage/$mapfile"
mkdir -p "$dir_output/$output_subdir/"
output_map="$dir_output/$output_subdir/$mapfile"


# cause of some timing problems we wait a random number of 1-10 seconds
sleep $[($RANDOM % 10) + 1]

# check if we need to download
if [ ! -e "$download_map" ]
then
   # wait if another process is downloading it
   if [ -e "$download_map.tmp" ]
   then
      while [ ! -e "$download_map" ]
      do
          sleep 10
      done
   # download if we are the only one
   else
      touch "$download_map.tmp"
      wget -q --limit-rate=$wget_limit_rate "$url_map" -O "$download_map.tmp"
      mv -f "$download_map.tmp" "$download_map"
   fi
fi

# download poly-file
wget -q --limit-rate=$wget_limit_rate "$url_poly" -O "$download_poly"

echo "start: $(date)" >> "$stage_map.time"
if [ "$use_poly" = "true" ]
then
   echo "command: $osmosis_executable --rb \"$download_map\" --bp clipIncompleteEntities=true file=\"$download_poly\" --mw file=\"$stage_map\" type=\"$wm_type\" map-start-zoom=\"$start_zoom\" preferred-language=\"$language\"" >> "$stage_map.time"
   $osmosis_executable --rb "$download_map" --bp clipIncompleteEntities=true file="$download_poly" --mw file="$stage_map" type="$wm_type" map-start-zoom="$start_zoom" preferred-language="$language" > "$stage_map.log" 2>&1
   ret=$?
else
   echo "command: $osmosis_executable --rb \"$download_map\" --mw file=\"$stage_map\" type=\"$wm_type\" map-start-zoom=\"$start_zoom\" preferred-language=\"$language\"" >> "$stage_map.time"
   $osmosis_executable --rb "$download_map" --mw file="$stage_map" type="$wm_type" map-start-zoom="$start_zoom" preferred-language="$language" > "$stage_map.log" 2>&1
   ret=$?
fi
echo "end: $(date)" >> "$stage_map.time"

if [ $ret -eq 0 ]
then
   mv -f "$stage_map" "$output_map"
   rm -f "$stage_map.log"
fi