-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmapdata.py
119 lines (84 loc) · 2.9 KB
/
mapdata.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import configparser
import time
WORK_DIR = os.path.expanduser('~') + "/map_build/"
def info(msg):
print("II: " + msg)
def warn(msg):
print("WW: " + msg)
def error(msg):
print("EE: " + msg)
# configparser
def write_config():
with open('pygmap3.cfg', 'w') as configfile:
config.write(configfile)
config = configparser.ConfigParser()
def create_o5m():
os.chdir(WORK_DIR)
config.read('pygmap3.cfg')
region = config['runtime']['region']
if os.path.exists("planet/planet-latest.osm.pbf"):
os.remane("planet-latest.osm.pbf", "planet.osm.pbf")
if not os.path.exists("poly/" + region + ".poly"):
print()
error("No poly file for " + region + " found!")
print()
quit()
for planet in ["planet/planet.o5m", "planet/planet.osm.pbf"]:
if os.path.exists(planet):
ftime = os.path.getmtime(planet)
curtime = time.time()
difftime = curtime - ftime
if difftime > 1741800:
print()
warn("Your planet file is older then one month")
print(" You should update it.")
print()
info("now extracting " + region
+ ".o5m from Planet, please wait...")
os.system("osmconvert " + planet + " "
+ "--complete-ways "
+ "--complete-multipolygons "
+ "--complete-boundaries "
+ "--drop-version "
+ "--drop-author "
+ "-B=poly/" + region + ".poly "
+ " -o=o5m/" + region + ".o5m ")
break
else:
print()
error("No planet file found, couldn't extract the raw data!")
print()
quit()
def update_o5m():
os.chdir(WORK_DIR)
config.read('pygmap3.cfg')
region = config['runtime']['region']
if config.has_option('runtime', 'minutely'):
update_opts = " --hourly -- minutely "
elif config.has_option('runtime', 'hourly'):
update_opts = " --hourly "
else:
update_opts = " "
print()
info("updating " + region + ".o5m, please wait...")
poly = " "
if os.path.exists("poly/" + region + ".poly"):
poly = " -B=poly/" + region + ".poly "
os.system("osmupdate --daily "
+ "--drop-version "
+ "--drop-author "
+ update_opts
+ poly
+ "--keep-tempfiles "
+ "o5m/" + region + ".o5m o5m/" + region + "_new.o5m")
os.chdir("o5m")
if os.path.exists(region + "_new.o5m"):
os.rename(region + ".o5m", region + "_temp.o5m")
os.rename(region + "_new.o5m", region + ".o5m")
if os.path.exists(region + ".o5m"):
os.remove(region + "_temp.o5m")
os.chdir(WORK_DIR)
write_config()