-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharea-to-gpx.py
78 lines (67 loc) · 2.22 KB
/
area-to-gpx.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
#!/usr/bin/python
import json
import errno
import os
import os.path
import datetime
import sys
import getopt
import lib.filehelper
import lib.config
import lib.mapillary
import lib.gpxutils
if __name__ == "__main__":
cache_folder = None
def print_help():
print """Usage: area-to-gpx.py [-h | -v] -c client_id min_lat,min_lon,max_lat,max_lon output_file
Options:
-c --client-id Give the client ID used for accessing the Mapillary API.
This argument must be given the first time the script is used,
then it is saved in a configuration file.
-h --help Print this message and exit.
-v --verbose Print extra info.
"""
verbose = 0
seq_id = None
output_file = None
client_id = None
try:
opts, args = getopt.getopt(sys.argv[1:], "hvc:",
["help", "verbose", "cache-dir", "client-id:"])
except getopt.GetoptError, err:
print str(err)
sys.exit(2)
for switch, value in opts:
if switch in ("-h", "--help"):
print_help()
sys.exit(0)
elif switch in ("-v", "--verbose"):
verbose += 1
elif switch in ("-c", "--client-id"):
client_id = value
elif switch in ("--cache-dir"):
cache_folder = value
if len(args) != 2:
print "2 arguments must be given:"
print_help()
sys.exit(1)
else:
latlon = args[0]
output_file = args[1]
if len(latlon.split(',')) != 4:
print "The lat/lon... argument must contain 4 numbers separated by only a , and no spaces."
print_help()
sys.exit(1)
(min_lat,min_lon,max_lat,max_lon) = latlon.split(',')
config = lib.config.MapillaryConfig()
if client_id == None:
client_id = config.getClientID()
else:
config.setClientID(client_id)
config.save()
m = lib.mapillary.MapillaryRequest(client_id)
file_helper = lib.filehelper.FileHelper()
coords = m.get_sequences_in_area(min_lat,min_lon,max_lat,max_lon)
gpxutil = lib.gpxutils.GpxUtil()
gpxobj = gpxutil.coords_2_sequences(coords)
file_helper.save_file(gpxobj.to_xml(), output_file)