-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontourlines.py
167 lines (120 loc) · 4.63 KB
/
contourlines.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import configparser
import shutil
def info(msg):
print("II: " + msg)
def warn(msg):
print("WW: " + msg)
def error(msg):
print("EE: " + msg)
def checkprg(programmtofind, solutionhint):
# test if an executable can be found by
# following $PATH
# raise message if fails and returns 1
# on success return 0
# search follows $PATH
if os.system("which " + programmtofind) == 0:
info(programmtofind + " found")
else:
error(programmtofind + " not found")
print(solutionhint)
def is_there(find, solutionhint):
# test if a file or dir can be found at a predefined place
# raise message if fails and returns 1
# on success return 0
if os.path.exists(find):
info(find + " found")
else:
error(find + " not found")
print(solutionhint)
WORK_DIR = os.path.expanduser('~') + "/map_build/"
config = configparser.ConfigParser()
# create the contourlines
def create_cont():
os.chdir(WORK_DIR)
config.read('pygmap3.cfg')
region = config['runtime']['region']
cl_dir = "gps_ready/zipped/" + region + "/"
cltemp_dir = "cl_temp/"
for dir in [cltemp_dir, cl_dir]:
if not os.path.exists(dir):
os.makedirs(dir)
path = cltemp_dir
for file in os.listdir(path):
if os.path.isfile(os.path.join(path, file)):
os.remove(os.path.join(path, file))
if not os.path.exists(cl_dir + region +
"_contourlines_gmapsupp.img.zip"):
hint = "Install phyghtmap to create contourlines if needed"
checkprg("phyghtmap", hint)
if not os.path.exists("styles/contourlines_style/lines"):
error("No contourlines_style found")
quit()
if config.has_option('maxnodes', region):
maxnodes = config['maxnodes'][region]
else:
maxnodes = config['maxnodes']['default']
# use phyghtmap to get the raw-data from the internet,
# downloaded files will be stored for later builds
command_line = ("phyghtmap --source=view1,view3,srtm1"
+ " --start-node-id=1 "
+ " --start-way-id=1 "
+ " --max-nodes-per-tile="
+ maxnodes
+ " --max-nodes-per-way=250 "
+ " --jobs=4 "
+ " --o5m "
+ " --no-zero-contour "
+ " -s 50 "
+ " -c 500,100 "
+ " --polygon=poly/" + region + ".poly "
+ " -o " + cltemp_dir + region)
if config.has_option('runtime', 'verbose'):
print()
info(command_line)
print()
os.system(command_line)
# Java HEAP, RAM oder Mode
if config['java']['agh'] == "1":
heap = " -XX:+AggressiveHeap "
else:
heap = (config['java']['xmx'] + " " + config['java']['xms'])
# contourlines-build with mkgmap
os.chdir(cltemp_dir)
mkgmap = WORK_DIR + config['mkgmap']['rev'] + "/mkgmap.jar "
command_line = ("java -ea "
+ heap
+ " -jar " + mkgmap
+ " --max-jobs "
+ " --read-config="
+ WORK_DIR + "styles/contourlines_style/options"
+ " --style-file="
+ WORK_DIR + "styles/contourlines_style"
+ " --mapname="
+ config[region]['mapid'] + "8001"
+ " --description="
+ region + "_contourlines "
+ " --family-name=Contourlines"
+ " --draw-priority="
+ config['contourlines']['draw-priority']
+ " --gmapsupp "
+ " *.o5m ")
if config.has_option('runtime', 'verbose'):
print()
info(command_line)
print()
os.system(command_line)
import zipfile
img = region + "_contourlines_gmapsupp.img"
shutil.move("gmapsupp.img", img)
zip_img = img + ".zip"
my_zip_img = zipfile.ZipFile(zip_img, 'w', allowZip64=True)
my_zip_img.write(img, compress_type=zipfile.ZIP_DEFLATED)
my_zip_img.close()
if os.path.exists(zip_img):
os.remove(img)
os.chdir(WORK_DIR)
file = "_contourlines_gmapsupp.img.zip"
shutil.move(cltemp_dir + region + file, cl_dir + region + file)