gpx 0.8.3 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +37 -0
- data/.gitignore +4 -0
- data/.rubocop +1 -0
- data/.rubocop.yml +162 -0
- data/.ruby-version +1 -0
- data/.tool-versions +1 -0
- data/.travis.yml +4 -6
- data/CHANGELOG.md +32 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +1 -1
- data/README.md +38 -17
- data/Rakefile +22 -12
- data/UPGRADING.md +7 -0
- data/bin/gpx_distance +5 -6
- data/bin/gpx_smooth +25 -26
- data/gpx.gemspec +14 -11
- data/lib/gpx/bounds.rb +13 -31
- data/lib/gpx/geo_json.rb +199 -0
- data/lib/gpx/gpx.rb +4 -26
- data/lib/gpx/gpx_file.rb +140 -134
- data/lib/gpx/magellan_track_log.rb +34 -66
- data/lib/gpx/point.rb +22 -35
- data/lib/gpx/route.rb +10 -31
- data/lib/gpx/segment.rb +63 -90
- data/lib/gpx/track.rb +38 -42
- data/lib/gpx/track_point.rb +32 -0
- data/lib/gpx/version.rb +3 -1
- data/lib/gpx/waypoint.rb +10 -34
- data/lib/gpx.rb +13 -34
- data/tests/geojson_files/combined_data.json +68 -0
- data/tests/geojson_files/line_string_data.json +83 -0
- data/tests/geojson_files/multi_line_string_data.json +74 -0
- data/tests/geojson_files/multi_point_data.json +14 -0
- data/tests/geojson_files/point_data.json +22 -0
- data/tests/geojson_test.rb +92 -0
- data/tests/gpx10_test.rb +7 -6
- data/tests/gpx_file_test.rb +31 -19
- data/tests/gpx_files/one_segment_mixed_times.gpx +884 -0
- data/tests/gpx_files/routes_without_names.gpx +29 -0
- data/tests/gpx_files/with_empty_tracks.gpx +72 -0
- data/tests/magellan_test.rb +12 -11
- data/tests/output_test.rb +93 -94
- data/tests/route_test.rb +75 -30
- data/tests/segment_test.rb +104 -93
- data/tests/track_file_test.rb +50 -70
- data/tests/track_point_test.rb +22 -11
- data/tests/track_test.rb +73 -61
- data/tests/waypoint_test.rb +46 -48
- metadata +45 -13
- data/lib/gpx/trackpoint.rb +0 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b894a8f06a91646472aa6311602be3da1c0d4767a7bc44867ba954ecf93d1909
|
4
|
+
data.tar.gz: 73b5b4e73fb783f3e10a007e2101f49db0e57f48e3675fea7b8255d1a21b84ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 279dff5711fc5808537e5e69d9be696dc9439b899021f5ab3a7532a8c68d5c099a40b63fefd89d7ebba1c64c250e599211f4a157028d4f00663b41a77cbf4ae6
|
7
|
+
data.tar.gz: b0c69fe2fa5014edb2e3628fc73b949b1d9fdaad5e73ab7546e7fd74d47c295be5722451cb8cd7cec5ebeb7ba85cc32e9ac38682d9b72b6e223f0b3295e594a1
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ master ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ master ]
|
15
|
+
workflow_dispatch:
|
16
|
+
|
17
|
+
jobs:
|
18
|
+
test:
|
19
|
+
|
20
|
+
runs-on: ubuntu-latest
|
21
|
+
strategy:
|
22
|
+
fail-fast: true
|
23
|
+
matrix:
|
24
|
+
ruby-version: ['2.7', '3.0', '3.1', '3.2']
|
25
|
+
|
26
|
+
steps:
|
27
|
+
- uses: actions/checkout@v2
|
28
|
+
- name: Set up Ruby
|
29
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
30
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
31
|
+
# uses: ruby/setup-ruby@v1
|
32
|
+
uses: ruby/setup-ruby@v1.149.0
|
33
|
+
with:
|
34
|
+
ruby-version: ${{ matrix.ruby-version }}
|
35
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
36
|
+
- name: Run tests
|
37
|
+
run: bundle exec rake
|
data/.gitignore
CHANGED
data/.rubocop
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--server
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.7
|
3
|
+
|
4
|
+
Style/Alias:
|
5
|
+
Enabled: false
|
6
|
+
StyleGuide: http://relaxed.ruby.style/#stylealias
|
7
|
+
|
8
|
+
Style/AsciiComments:
|
9
|
+
Enabled: false
|
10
|
+
StyleGuide: http://relaxed.ruby.style/#styleasciicomments
|
11
|
+
|
12
|
+
Style/BeginBlock:
|
13
|
+
Enabled: false
|
14
|
+
StyleGuide: http://relaxed.ruby.style/#stylebeginblock
|
15
|
+
|
16
|
+
Style/BlockDelimiters:
|
17
|
+
Enabled: false
|
18
|
+
StyleGuide: http://relaxed.ruby.style/#styleblockdelimiters
|
19
|
+
|
20
|
+
Style/CommentAnnotation:
|
21
|
+
Enabled: false
|
22
|
+
StyleGuide: http://relaxed.ruby.style/#stylecommentannotation
|
23
|
+
|
24
|
+
Style/Documentation:
|
25
|
+
Enabled: false
|
26
|
+
StyleGuide: http://relaxed.ruby.style/#styledocumentation
|
27
|
+
|
28
|
+
Layout/DotPosition:
|
29
|
+
Enabled: false
|
30
|
+
StyleGuide: http://relaxed.ruby.style/#layoutdotposition
|
31
|
+
|
32
|
+
Style/DoubleNegation:
|
33
|
+
Enabled: false
|
34
|
+
StyleGuide: http://relaxed.ruby.style/#styledoublenegation
|
35
|
+
|
36
|
+
Style/EndBlock:
|
37
|
+
Enabled: false
|
38
|
+
StyleGuide: http://relaxed.ruby.style/#styleendblock
|
39
|
+
|
40
|
+
Style/FormatString:
|
41
|
+
Enabled: false
|
42
|
+
StyleGuide: http://relaxed.ruby.style/#styleformatstring
|
43
|
+
|
44
|
+
Style/IfUnlessModifier:
|
45
|
+
Enabled: false
|
46
|
+
StyleGuide: http://relaxed.ruby.style/#styleifunlessmodifier
|
47
|
+
|
48
|
+
Style/Lambda:
|
49
|
+
Enabled: false
|
50
|
+
StyleGuide: http://relaxed.ruby.style/#stylelambda
|
51
|
+
|
52
|
+
Style/ModuleFunction:
|
53
|
+
Enabled: false
|
54
|
+
StyleGuide: http://relaxed.ruby.style/#stylemodulefunction
|
55
|
+
|
56
|
+
Style/MultilineBlockChain:
|
57
|
+
Enabled: false
|
58
|
+
StyleGuide: http://relaxed.ruby.style/#stylemultilineblockchain
|
59
|
+
|
60
|
+
Style/NegatedIf:
|
61
|
+
Enabled: false
|
62
|
+
StyleGuide: http://relaxed.ruby.style/#stylenegatedif
|
63
|
+
|
64
|
+
Style/NegatedWhile:
|
65
|
+
Enabled: false
|
66
|
+
StyleGuide: http://relaxed.ruby.style/#stylenegatedwhile
|
67
|
+
|
68
|
+
Style/ParallelAssignment:
|
69
|
+
Enabled: false
|
70
|
+
StyleGuide: http://relaxed.ruby.style/#styleparallelassignment
|
71
|
+
|
72
|
+
Style/PercentLiteralDelimiters:
|
73
|
+
Enabled: false
|
74
|
+
StyleGuide: http://relaxed.ruby.style/#stylepercentliteraldelimiters
|
75
|
+
|
76
|
+
Style/PerlBackrefs:
|
77
|
+
Enabled: false
|
78
|
+
StyleGuide: http://relaxed.ruby.style/#styleperlbackrefs
|
79
|
+
|
80
|
+
Style/Semicolon:
|
81
|
+
Enabled: false
|
82
|
+
StyleGuide: http://relaxed.ruby.style/#stylesemicolon
|
83
|
+
|
84
|
+
Style/SignalException:
|
85
|
+
Enabled: false
|
86
|
+
StyleGuide: http://relaxed.ruby.style/#stylesignalexception
|
87
|
+
|
88
|
+
Style/SingleLineBlockParams:
|
89
|
+
Enabled: false
|
90
|
+
StyleGuide: http://relaxed.ruby.style/#stylesinglelineblockparams
|
91
|
+
|
92
|
+
Style/SingleLineMethods:
|
93
|
+
Enabled: false
|
94
|
+
StyleGuide: http://relaxed.ruby.style/#stylesinglelinemethods
|
95
|
+
|
96
|
+
Layout/SpaceBeforeBlockBraces:
|
97
|
+
Enabled: false
|
98
|
+
StyleGuide: http://relaxed.ruby.style/#layoutspacebeforeblockbraces
|
99
|
+
|
100
|
+
Layout/SpaceInsideParens:
|
101
|
+
Enabled: false
|
102
|
+
StyleGuide: http://relaxed.ruby.style/#layoutspaceinsideparens
|
103
|
+
|
104
|
+
Style/SpecialGlobalVars:
|
105
|
+
Enabled: false
|
106
|
+
StyleGuide: http://relaxed.ruby.style/#stylespecialglobalvars
|
107
|
+
|
108
|
+
Style/StringLiterals:
|
109
|
+
Enabled: false
|
110
|
+
StyleGuide: http://relaxed.ruby.style/#stylestringliterals
|
111
|
+
|
112
|
+
Style/WhileUntilModifier:
|
113
|
+
Enabled: false
|
114
|
+
StyleGuide: http://relaxed.ruby.style/#stylewhileuntilmodifier
|
115
|
+
|
116
|
+
Style/WordArray:
|
117
|
+
Enabled: false
|
118
|
+
StyleGuide: http://relaxed.ruby.style/#stylewordarray
|
119
|
+
|
120
|
+
Lint/AmbiguousRegexpLiteral:
|
121
|
+
Enabled: false
|
122
|
+
StyleGuide: http://relaxed.ruby.style/#lintambiguousregexpliteral
|
123
|
+
|
124
|
+
Lint/AssignmentInCondition:
|
125
|
+
Enabled: false
|
126
|
+
StyleGuide: http://relaxed.ruby.style/#lintassignmentincondition
|
127
|
+
|
128
|
+
Metrics/AbcSize:
|
129
|
+
Enabled: false
|
130
|
+
|
131
|
+
Metrics/BlockNesting:
|
132
|
+
Enabled: false
|
133
|
+
|
134
|
+
Metrics/ClassLength:
|
135
|
+
Enabled: false
|
136
|
+
|
137
|
+
Metrics/ModuleLength:
|
138
|
+
Enabled: false
|
139
|
+
|
140
|
+
Metrics/CyclomaticComplexity:
|
141
|
+
Enabled: false
|
142
|
+
|
143
|
+
Metrics/LineLength:
|
144
|
+
Enabled: false
|
145
|
+
|
146
|
+
Metrics/MethodLength:
|
147
|
+
Enabled: false
|
148
|
+
|
149
|
+
Metrics/ParameterLists:
|
150
|
+
Enabled: false
|
151
|
+
|
152
|
+
Metrics/PerceivedComplexity:
|
153
|
+
Enabled: false
|
154
|
+
|
155
|
+
Naming/MethodParameterName:
|
156
|
+
Enabled: false
|
157
|
+
|
158
|
+
Naming/VariableNumber:
|
159
|
+
Enabled: false
|
160
|
+
|
161
|
+
Style/DateTime:
|
162
|
+
Enabled: false
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.2
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 3.2.2
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,35 @@
|
|
1
|
+
## [1.1.1] - 2023-05-19
|
2
|
+
|
3
|
+
* updates CI, minimal Ruby version now 2.7, updates tooling like rubocop and GitHub actions
|
4
|
+
* adds support for Ruby 3.2
|
5
|
+
* adds UPGRADING.md to document changes between versions
|
6
|
+
|
7
|
+
## [1.1.0] - 2023-05-18
|
8
|
+
* Specify UTF-8 encoding for XML encoding (#35 via @sh1nduu)
|
9
|
+
* Added GeoJSON conversion (#38 via @tyrauber and @niborg)
|
10
|
+
* Support Ruby 3 (#43 via @LocoDelAssembly)
|
11
|
+
* Fix nil-to-Time comparison (#46 via @frodrigo)
|
12
|
+
* Fix bug when <rte> GPX file does not specify <name> tag (#41 via @niborg)
|
13
|
+
* Drop Ruby 2.5 and 2.6 from CI (#50 via @niborg)
|
14
|
+
|
15
|
+
## [1.0.0] - 2018-03-06
|
16
|
+
|
17
|
+
* Fix duplication of points on appending segment to track (#20 via @niborg)
|
18
|
+
* Remove pythagorean distance (#28 fixing #27, via @moveson)
|
19
|
+
* Ignore empty segments (#29 via @nathanvda)
|
20
|
+
* Introduce Rubocop (#31)
|
21
|
+
* Explicit test support for Ruby 2.5 (#30)
|
22
|
+
|
23
|
+
## [0.9.0] - 2017-01-05
|
24
|
+
|
25
|
+
* Upgrade Nokogiri deps to be more explicit, then explicitly bump the Ruby
|
26
|
+
dependency.
|
27
|
+
|
28
|
+
## [0.8.3] - 2017-01-05
|
29
|
+
|
30
|
+
* Make Track comment and description fields be `attr_accessible` (#17 via
|
31
|
+
@wallclimber21)
|
32
|
+
|
1
33
|
## [0.8.2] - 2015-08-03
|
2
34
|
|
3
35
|
* Enhance calculation of average speed (with usage of new
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -3,10 +3,6 @@
|
|
3
3
|
[<img src="https://travis-ci.org/dougfales/gpx.svg" alt="Build Status" />](https://travis-ci.org/dougfales/gpx)
|
4
4
|
[](https://codeclimate.com/github/dougfales/gpx)
|
5
5
|
|
6
|
-
Copyright (C) 2006 Doug Fales doug@falesafeconsulting.com
|
7
|
-
|
8
|
-
Released under the MIT License.
|
9
|
-
|
10
6
|
## What It Does
|
11
7
|
|
12
8
|
This library reads GPX files and provides an API for reading and manipulating
|
@@ -14,14 +10,24 @@ the data as objects. For more info on the GPX format, see
|
|
14
10
|
http://www.topografix.com/gpx.asp.
|
15
11
|
|
16
12
|
In addition to parsing GPX files, this library is capable of converting
|
17
|
-
Magellan NMEA files to GPX,
|
18
|
-
|
19
|
-
the tracks and points in a file (such as distance, duration, average speed,
|
20
|
-
|
13
|
+
Magellan NMEA files to GPX, converting GeoJSON data to GPX, and writing
|
14
|
+
new GPX files. It can crop and delete rectangular areas within a file,
|
15
|
+
and it also calculates some meta-data about the tracks and points in a file (such as distance, duration, average speed, etc).
|
16
|
+
|
17
|
+
## Requirements
|
21
18
|
|
19
|
+
- As of `1.1.1`, `gpx` requires at least Ruby 2.7 to run.
|
20
|
+
- As of `1.0.0`, `gpx` requires at least Ruby 2.2 to run.
|
21
|
+
|
22
|
+
## Installation
|
23
|
+
Add to your gemfile:
|
24
|
+
```
|
25
|
+
gem 'gpx'
|
26
|
+
```
|
22
27
|
## Examples
|
23
28
|
|
24
29
|
Reading a GPX file, and cropping its contents to a given area:
|
30
|
+
|
25
31
|
```ruby
|
26
32
|
gpx = GPX::GPXFile.new(:gpx_file => filename) # Read GPX file
|
27
33
|
bounds = GPX::Bounds.new(params) # Create a rectangular area to crop
|
@@ -36,33 +42,44 @@ if GPX::MagellanTrackLog::is_magellan_file?(filename)
|
|
36
42
|
end
|
37
43
|
```
|
38
44
|
|
45
|
+
Converting GeoJSON data to GPX can be achieved by providing a
|
46
|
+
file path, file, or the data in string format:
|
47
|
+
```ruby
|
48
|
+
# Converting from a file name
|
49
|
+
gpx_file = GPX::GeoJSON.convert_to_gpx(geojson_file: 'mygeojsonfile.json')
|
50
|
+
|
51
|
+
# Converting from a string
|
52
|
+
data = JSON.generate(my_geojson_hash)
|
53
|
+
gpx_file = GPX::GeoJSON.convert_to_gpx(geojson_data: data)
|
54
|
+
```
|
55
|
+
|
39
56
|
Exporting an ActiveRecord to GPXFile (as Waypoints)
|
40
57
|
```ruby
|
41
58
|
#
|
42
59
|
# Our active record in this example is called stop
|
43
60
|
#
|
44
|
-
|
45
|
-
# models/stop.rb
|
61
|
+
|
62
|
+
# models/stop.rb
|
46
63
|
class Stop < ActiveRecord::Base
|
47
64
|
# This model has the following attributes:
|
48
65
|
# name
|
49
66
|
# lat
|
50
67
|
# lon
|
51
68
|
# updated_at
|
52
|
-
|
69
|
+
|
53
70
|
def self.to_gpx
|
54
71
|
require 'GPX'
|
55
72
|
gpx = GPX::GPXFile.new
|
56
73
|
all.each do |stop|
|
57
74
|
gpx.waypoints << GPX::Waypoint.new({name: stop.name, lat: stop.lat, lon: stop.lon, time: stop.updated_at})
|
58
|
-
end
|
75
|
+
end
|
59
76
|
gpx.to_s
|
60
77
|
end
|
61
78
|
end # class
|
62
79
|
|
63
80
|
|
64
81
|
# controllers/stops.rb
|
65
|
-
def index
|
82
|
+
def index
|
66
83
|
@stops = Stop.all
|
67
84
|
respond_to do |format|
|
68
85
|
format.html {render :index}
|
@@ -73,8 +90,8 @@ end
|
|
73
90
|
|
74
91
|
# Add this line to config/initializers/mime_types.rb
|
75
92
|
Mime::Type.register "application/gpx+xml", :gpx
|
76
|
-
|
77
|
-
|
93
|
+
|
94
|
+
|
78
95
|
# To get the xml file:
|
79
96
|
# http://localhost:3000/stops.gpx
|
80
97
|
```
|
@@ -88,13 +105,17 @@ This library was written to bridge the gap between my Garmin Geko
|
|
88
105
|
and my website, WalkingBoss.org (RIP). For that reason, it has always been more of a
|
89
106
|
work-in-progress than an attempt at full GPX compliance. The track side of the
|
90
107
|
library has seen much more use than the route/waypoint side, so if you're doing
|
91
|
-
something with routes or waypoints, you may need to tweak some things.
|
108
|
+
something with routes or waypoints, you may need to tweak some things.
|
92
109
|
|
93
110
|
Since this code uses XML to read an entire GPX file into memory, it is not
|
94
111
|
the fastest possible solution for working with GPX data, especially if you are
|
95
|
-
working with tracks from several days or weeks.
|
112
|
+
working with tracks from several days or weeks.
|
96
113
|
|
97
114
|
Finally, it should be noted that none of the distance/speed calculation or
|
98
115
|
crop/delete code has been tested under International Date Line-crossing
|
99
116
|
conditions. That particular part of the code will likely be unreliable if
|
100
117
|
you're zig-zagging across 180 degrees longitude routinely.
|
118
|
+
|
119
|
+
## License
|
120
|
+
|
121
|
+
MIT
|
data/Rakefile
CHANGED
@@ -1,31 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler/gem_tasks'
|
2
4
|
require 'rake/testtask'
|
3
5
|
require 'rdoc/task'
|
6
|
+
require 'rubocop/rake_task'
|
7
|
+
|
8
|
+
RuboCop::RakeTask.new
|
4
9
|
|
5
|
-
desc
|
6
|
-
task :
|
10
|
+
desc 'Default Task'
|
11
|
+
task default: %i[test rubocop]
|
7
12
|
|
8
13
|
namespace :ci do
|
9
14
|
task :build do
|
10
|
-
puts
|
11
|
-
FileUtils.mkdir_p
|
15
|
+
puts 'Creating tests/output directory...'
|
16
|
+
FileUtils.mkdir_p 'tests/output'
|
12
17
|
Rake::Task[:test].invoke
|
13
18
|
end
|
14
19
|
end
|
15
20
|
|
16
21
|
# Run the unit tests
|
17
|
-
desc
|
18
|
-
Rake::TestTask.new(
|
19
|
-
t.libs <<
|
22
|
+
desc 'Run all unit tests'
|
23
|
+
Rake::TestTask.new('test') do |t|
|
24
|
+
t.libs << 'lib'
|
20
25
|
t.pattern = 'tests/*_test.rb'
|
21
26
|
t.verbose = true
|
22
|
-
|
27
|
+
end
|
23
28
|
|
24
29
|
# Genereate the RDoc documentation
|
25
|
-
desc
|
26
|
-
Rake::RDocTask.new(
|
27
|
-
rdoc.title =
|
30
|
+
desc 'Create documentation'
|
31
|
+
Rake::RDocTask.new('doc') do |rdoc|
|
32
|
+
rdoc.title = 'Ruby GPX API'
|
28
33
|
rdoc.rdoc_dir = 'html'
|
29
34
|
rdoc.rdoc_files.include('README')
|
30
35
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
31
|
-
|
36
|
+
end
|
37
|
+
|
38
|
+
desc 'open an irb session preloaded with this gem'
|
39
|
+
task :console do
|
40
|
+
sh 'irb -r pp -r ./lib/gpx.rb'
|
41
|
+
end
|
data/UPGRADING.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# Upgrading
|
2
|
+
|
3
|
+
You will find all the information you need to upgrade from one version to another here.
|
4
|
+
|
5
|
+
## Version 1.0.0 to 1.1.1
|
6
|
+
|
7
|
+
Please make sure, that you need at least Ruby 2.7.0 to use this gem now. As support for Ruby versions below 2.7.0 has been dropped.
|
data/bin/gpx_distance
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require File.expand_path('../../lib/gpx', __FILE__)
|
4
|
-
|
5
|
-
filename = ARGV[0]
|
6
|
-
gpx = GPX::GPXFile.new(:gpx_file => filename)
|
7
|
-
puts "read track with distance #{gpx.distance}"
|
8
2
|
|
3
|
+
# frozen_string_literal: true
|
9
4
|
|
5
|
+
require File.expand_path('../lib/gpx', __dir__)
|
10
6
|
|
7
|
+
filename = ARGV[0]
|
8
|
+
gpx = GPX::GPXFile.new(gpx_file: filename)
|
9
|
+
puts "read track with distance #{gpx.distance}"
|
data/bin/gpx_smooth
CHANGED
@@ -1,63 +1,62 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require File.expand_path('../../lib/gpx', __FILE__)
|
4
|
-
require 'optparse'
|
5
2
|
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require File.expand_path('../lib/gpx', __dir__)
|
6
|
+
require 'optparse'
|
6
7
|
|
7
8
|
def str_to_int_or_time(str)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
case str
|
10
|
+
when /\A\d{10}\Z/
|
11
|
+
Time.at(str.to_i)
|
12
|
+
when /\A\d+\Z/
|
13
|
+
str.to_i
|
12
14
|
else
|
13
|
-
|
15
|
+
DateTime.strptime(str, '%Y%m%d-%H:%M:%S').to_time
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
|
-
|
18
19
|
options = {}
|
19
20
|
OptionParser.new do |opts|
|
20
|
-
opts.banner =
|
21
|
+
opts.banner = 'Usage: smooth [options]'
|
21
22
|
|
22
|
-
opts.on(
|
23
|
+
opts.on('-i', '--input-file FILE', 'Input file to read gpx data from (if omitted, data will be read from stdin)') do |v|
|
23
24
|
options[:infile] = v
|
24
25
|
end
|
25
|
-
opts.on(
|
26
|
+
opts.on('-o', '--output-file FILE', 'Output file to write smoothed gpx data to (if omitted, data will be written to stdout)') do |v|
|
26
27
|
options[:outfile] = v
|
27
28
|
end
|
28
|
-
opts.on(
|
29
|
+
opts.on('-s', '--start-time [YYYYMMDD-HH:MM:SS|EPOCH|OFFSET]', 'Start smoothing from time or offset specified (if omitted start from the start of the file)') do |v|
|
29
30
|
options[:start] = v
|
30
31
|
end
|
31
|
-
opts.on(
|
32
|
+
opts.on('-e', '--end-time [YYYYMMDD-HH:MM:SS|EPOCH|OFFSET]', 'Finish smoothing from time or offset specified (if omitted finish at the end of the file)') do |v|
|
32
33
|
options[:end] = v
|
33
34
|
end
|
34
35
|
end.parse!
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
37
|
+
input = if options[:infile]
|
38
|
+
File.open(options[:infile])
|
39
|
+
else
|
40
|
+
$stdin
|
41
|
+
end
|
42
42
|
|
43
43
|
options[:start] = str_to_int_or_time(options[:start]) if options[:start]
|
44
44
|
options[:end] = str_to_int_or_time(options[:end]) if options[:end]
|
45
45
|
|
46
|
-
gpx =
|
47
|
-
|
46
|
+
gpx = GPX::GPXFile.new(gpx_data: input)
|
47
|
+
warn "read track with distance #{gpx.distance}"
|
48
48
|
|
49
|
-
#1419062980
|
49
|
+
# 1419062980
|
50
50
|
gpx.tracks.each do |track|
|
51
51
|
track.segments.each do |segment|
|
52
|
-
segment.smooth_location_by_average(
|
52
|
+
segment.smooth_location_by_average(end: options[:end], start: options[:start])
|
53
53
|
end
|
54
54
|
end
|
55
55
|
gpx.recalculate_distance
|
56
|
-
|
56
|
+
warn "smoothed distance #{gpx.distance}"
|
57
57
|
|
58
58
|
if options[:outfile]
|
59
59
|
gpx.write(options[:outfile], false)
|
60
60
|
else
|
61
61
|
puts gpx.to_s(false)
|
62
62
|
end
|
63
|
-
|
data/gpx.gemspec
CHANGED
@@ -1,24 +1,27 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'gpx/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |s|
|
7
8
|
s.name = 'gpx'
|
8
9
|
s.version = GPX::VERSION
|
9
|
-
s.authors = [
|
10
|
-
s.email = [
|
11
|
-
s.summary =
|
12
|
-
s.description =
|
10
|
+
s.authors = ['Guillaume Dott', 'Doug Fales', 'Andrew Hao']
|
11
|
+
s.email = ['guillaume+github@dott.fr', 'doug.fales@gmail.com', 'andrewhao@gmail.com']
|
12
|
+
s.summary = 'A basic API for reading and writing GPX files.'
|
13
|
+
s.description = 'A basic API for reading and writing GPX files.'
|
14
|
+
|
15
|
+
s.required_ruby_version = '>= 2.7', '< 4'
|
13
16
|
|
14
|
-
s.files = `git ls-files`.split(
|
17
|
+
s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
15
18
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
16
|
-
s.require_paths = [
|
17
|
-
s.has_rdoc = true
|
19
|
+
s.require_paths = ['lib']
|
18
20
|
|
19
|
-
s.homepage =
|
21
|
+
s.homepage = 'http://www.github.com/dougfales/gpx'
|
22
|
+
s.add_dependency 'nokogiri', '~>1.7'
|
20
23
|
s.add_dependency 'rake'
|
21
|
-
s.add_dependency 'nokogiri'
|
22
24
|
s.add_development_dependency 'bundler'
|
23
25
|
s.add_development_dependency 'minitest'
|
26
|
+
s.add_development_dependency 'rubocop'
|
24
27
|
end
|