gpx_track_generator 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +21 -1
- data/features/create_gpx_track_file.feature +54 -0
- data/lib/gpx_track_generator/api.rb +2 -2
- data/lib/gpx_track_generator/runner.rb +9 -2
- data/lib/gpx_track_generator/track.rb +19 -9
- data/lib/gpx_track_generator/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f388ed4e3ed7f6da7a73c5565ef060601e90e95e
|
4
|
+
data.tar.gz: 0e0fb882167e13b291fb3519b1f0380e5163c83a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82eb885c1a4d8836acd3f53aabd1cf8811936297d7144724f38bc599a81aa1b1a2ab3cc706000af20c7387528562b31f81e491cca2ebaa5514b6ac4a094f3866
|
7
|
+
data.tar.gz: 5633dbde493ade486f1c4029063310d9a373abdc98dbb8cfa3ab112f57066c57bb2b26ca9fa28de1dfee6bedc4815246e21c55b4d08ad039c30661bd2ab74f33
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -52,6 +52,20 @@ GpxTrackGenerator::Api.generate(
|
|
52
52
|
output_file: output_file,
|
53
53
|
reverse: true
|
54
54
|
)
|
55
|
+
|
56
|
+
*Single segment per Track*
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
input_files = %w(track1.gpx route2.gpx)
|
60
|
+
track_name = 'Track ABC'
|
61
|
+
output_file = 'my_track.gpx'
|
62
|
+
|
63
|
+
GpxTrackGenerator::Api.generate(
|
64
|
+
input_files: input_files,
|
65
|
+
track_name: track_name,
|
66
|
+
output_file: output_file,
|
67
|
+
single_segment: true
|
68
|
+
)
|
55
69
|
```
|
56
70
|
|
57
71
|
### CLI
|
@@ -71,7 +85,13 @@ gpx_track --name "Track Name" *.gpx
|
|
71
85
|
*Reverse track*
|
72
86
|
|
73
87
|
```
|
74
|
-
gpx_track --
|
88
|
+
gpx_track --reverse *.gpx
|
89
|
+
```
|
90
|
+
|
91
|
+
*Single Segment for the whole track*
|
92
|
+
|
93
|
+
```
|
94
|
+
gpx_track --single-segment *.gpx
|
75
95
|
```
|
76
96
|
|
77
97
|
## Contributing
|
@@ -70,3 +70,57 @@ Feature: Create GPX Track File
|
|
70
70
|
<ele>16.232316396783801</ele>
|
71
71
|
</trkpt>
|
72
72
|
"""
|
73
|
+
|
74
|
+
Scenario: Single segment
|
75
|
+
Given a gpx file named "track1.gpx"
|
76
|
+
And a gpx file named "track2.gpx"
|
77
|
+
When I successfully run `gpx_track g --single-segment track1.gpx track2.gpx`
|
78
|
+
Then the gpx file "track.gpx" should contain:
|
79
|
+
"""
|
80
|
+
<trkseg>
|
81
|
+
<trkpt lat="55.688634024660372" lon="-5.5744374090151107">
|
82
|
+
<name>WP 1</name>
|
83
|
+
<ele>15.232316396783801</ele>
|
84
|
+
</trkpt>
|
85
|
+
<trkpt lat="57.688634024660372" lon="-5.5744374090151107">
|
86
|
+
<name>WP 2</name>
|
87
|
+
<ele>15.232316396783801</ele>
|
88
|
+
</trkpt>
|
89
|
+
<trkpt lat="56.688634024660372" lon="-6.5744374090151107">
|
90
|
+
<name>WP 1</name>
|
91
|
+
<ele>16.232316396783801</ele>
|
92
|
+
</trkpt>
|
93
|
+
<trkpt lat="57.688634024660372" lon="-6.5744374090151107">
|
94
|
+
<name>WP 2</name>
|
95
|
+
<ele>16.232316396783801</ele>
|
96
|
+
</trkpt>
|
97
|
+
</trkseg>
|
98
|
+
"""
|
99
|
+
|
100
|
+
Scenario: One segment per track file
|
101
|
+
Given a gpx file named "track1.gpx"
|
102
|
+
And a gpx file named "track2.gpx"
|
103
|
+
When I successfully run `gpx_track g --single-segment=false track1.gpx track2.gpx`
|
104
|
+
Then the gpx file "track.gpx" should contain:
|
105
|
+
"""
|
106
|
+
<trkseg>
|
107
|
+
<trkpt lat="55.688634024660372" lon="-5.5744374090151107">
|
108
|
+
<name>WP 1</name>
|
109
|
+
<ele>15.232316396783801</ele>
|
110
|
+
</trkpt>
|
111
|
+
<trkpt lat="57.688634024660372" lon="-5.5744374090151107">
|
112
|
+
<name>WP 2</name>
|
113
|
+
<ele>15.232316396783801</ele>
|
114
|
+
</trkpt>
|
115
|
+
</trkseg>
|
116
|
+
<trkseg>
|
117
|
+
<trkpt lat="56.688634024660372" lon="-6.5744374090151107">
|
118
|
+
<name>WP 1</name>
|
119
|
+
<ele>16.232316396783801</ele>
|
120
|
+
</trkpt>
|
121
|
+
<trkpt lat="57.688634024660372" lon="-6.5744374090151107">
|
122
|
+
<name>WP 2</name>
|
123
|
+
<ele>16.232316396783801</ele>
|
124
|
+
</trkpt>
|
125
|
+
</trkseg>
|
126
|
+
"""
|
@@ -2,9 +2,9 @@
|
|
2
2
|
module GpxTrackGenerator
|
3
3
|
# Main api
|
4
4
|
module Api
|
5
|
-
def self.generate(input_files:, track_name:, output_file:, reverse: false)
|
5
|
+
def self.generate(input_files:, track_name:, output_file:, reverse: false, single_segment: true)
|
6
6
|
files = input_files.map { |f| GpxFile.new(File.expand_path(f)) }
|
7
|
-
track = Track.new(files, name: track_name, reverse: reverse)
|
7
|
+
track = Track.new(files, name: track_name, reverse: reverse, single_segment: single_segment)
|
8
8
|
|
9
9
|
File.write(output_file, track.to_s)
|
10
10
|
end
|
@@ -4,12 +4,19 @@ module GpxTrackGenerator
|
|
4
4
|
class Runner < Thor
|
5
5
|
option :file, default: 'track.gpx', desc: 'GPX track file name'
|
6
6
|
option :name, default: 'Track #1', required: true, desc: 'Name for track'
|
7
|
-
option :reverse, type: :boolean, desc: 'Reverse track'
|
7
|
+
option :reverse, type: :boolean, default: false, desc: 'Reverse track (default: false)'
|
8
|
+
option :single_segment, type: :boolean, default: false, desc: 'Only one track segment for the whole track. Otherwise one segment for each input file (default: true)'
|
8
9
|
argument :input_files, type: :array, desc: 'GPX track or route files'
|
9
10
|
|
10
11
|
desc 'generate', 'Generate gpx track'
|
11
12
|
def generate
|
12
|
-
Api.generate(
|
13
|
+
Api.generate(
|
14
|
+
input_files: input_files,
|
15
|
+
track_name: options[:name],
|
16
|
+
output_file: options[:file],
|
17
|
+
reverse: options[:reverse],
|
18
|
+
single_segment: options[:single_segment]
|
19
|
+
)
|
13
20
|
end
|
14
21
|
|
15
22
|
default_command :generate
|
@@ -4,14 +4,15 @@ module GpxTrackGenerator
|
|
4
4
|
class Track
|
5
5
|
private
|
6
6
|
|
7
|
-
attr_reader :files, :name, :reverse
|
7
|
+
attr_reader :files, :name, :reverse, :single_segment
|
8
8
|
|
9
9
|
public
|
10
10
|
|
11
|
-
def initialize(files, name:, reverse:)
|
12
|
-
@files
|
13
|
-
@name
|
14
|
-
@reverse
|
11
|
+
def initialize(files, name:, reverse:, single_segment:)
|
12
|
+
@files = files
|
13
|
+
@name = name
|
14
|
+
@reverse = reverse
|
15
|
+
@single_segment = single_segment
|
15
16
|
end
|
16
17
|
|
17
18
|
def to_s
|
@@ -35,10 +36,19 @@ module GpxTrackGenerator
|
|
35
36
|
document.css('trk').first << document.create_element('name')
|
36
37
|
document.css('name').first.content = name
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
if single_segment
|
40
|
+
document.css('trk').first << document.create_element('trkseg')
|
41
|
+
|
42
|
+
files.each_with_object(document.css('trk').first) do |e, a|
|
43
|
+
a << "<!-- #{e.file_name} -->"
|
44
|
+
document.css('trkseg').last << (reverse ? e.nodes.reverse : e.nodes)
|
45
|
+
end
|
46
|
+
else
|
47
|
+
files.each_with_object(document.css('trk').first) do |e, a|
|
48
|
+
a << "<!-- #{e.file_name} -->"
|
49
|
+
a << document.create_element('trkseg')
|
50
|
+
a.css('trkseg').last << (reverse ? e.nodes.reverse : e.nodes)
|
51
|
+
end
|
42
52
|
end
|
43
53
|
|
44
54
|
document.human
|