-
Notifications
You must be signed in to change notification settings - Fork 2
/
gpxdup
executable file
·101 lines (91 loc) · 2.57 KB
/
gpxdup
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
#!/usr/bin/env python
import argparse
import logging
import sys
import traceback
import gpxlib
def main():
parser = argparse.ArgumentParser(
description="A tool to remove and duplicate the first point(s) in a GPX file"
)
strip_group = parser.add_mutually_exclusive_group()
strip_group.add_argument(
"-s",
"--strip",
help="Strip first points before duplicating",
type=int,
default=gpxlib.DEFAULT_STRIP,
)
strip_group.add_argument(
"-m", "--smart-strip", help="Strip first points before duplicating"
)
parser.add_argument(
"-d",
"--duplicate",
help="Number of times to duplicate",
type=int,
default=gpxlib.DEFAULT_DUPLICATE,
)
parser.add_argument(
"-i",
"--shift",
help="Location shift for new GPX points, in 1/100000 latitude",
type=int,
default=gpxlib.DEFAULT_SHIFT,
)
parser.add_argument(
"-r",
"--smart-strip-radius",
help="Smart strip radius",
type=int,
default=gpxlib.DEFAULT_SMART_STRIP_RADIUS,
)
parser.add_argument(
"-l",
"--smart-strip-limit",
help="Smart strip limit",
type=int,
default=gpxlib.DEFAULT_SMART_STRIP_LIMIT,
)
parser.add_argument(
"-u",
"--smart-duplicate",
help="Set --duplicate to the number of smart stripped points",
action="store_true",
)
parser.add_argument("-o", "--output", help="Write output to OUTPUT")
parser.add_argument(
"-t",
"--time",
help="Time in ms to shift",
type=int,
default=gpxlib.DEFAULT_TIME,
)
parser.add_argument("file", nargs="?")
args = parser.parse_args()
logging.basicConfig(level=1, format="%(asctime)s -- %(message)s")
# read input, create GPX output
gpx_in, points = gpxlib.read(args.file)
gpx_out, segment = gpxlib.create(gpx_in)
try:
segment.points = gpxlib.gpxdup(
points,
strip=args.strip,
duplicate=args.duplicate,
time=args.time,
shift=args.shift,
smart_strip=args.smart_strip,
smart_strip_radius=args.smart_strip_radius,
smart_strip_limit=args.smart_strip_limit,
smart_duplicate=args.smart_duplicate,
)
except Exception:
sys.exit(traceback.format_exc())
s = gpx_out.to_xml()
if args.output:
with open(args.output, "w") as f:
f.write(s)
else:
print(s)
if __name__ == "__main__":
main()