gpx 0.9.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +36 -0
- data/.gitignore +4 -0
- data/.rubocop.yml +162 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -5
- data/CHANGELOG.md +15 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +1 -1
- data/README.md +20 -5
- data/Rakefile +22 -12
- data/bin/gpx_distance +5 -6
- data/bin/gpx_smooth +25 -26
- data/gpx.gemspec +13 -12
- 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 +47 -18
- 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: f206f4729605d96cdaf65fe3fe52237c14f61eb1ae69558eb826c6f831e4076b
|
4
|
+
data.tar.gz: b05a8fd9d66446f57640474b3dad428b5eab24617b2e0cb3b19e655d079ea0d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28c8c86253452eb56383790c43189de24929482781b5d94ac9416ab93be596fbbe5259e0226a18bbb7e44070503d6b721671bff2b239a5512a935fcb21dbc19f
|
7
|
+
data.tar.gz: be64658d5bf4cf3d7653b2457f286401971d3a7a272766002d78296341eedd2c4ad237dc5ac38d38debe7dd7288275185b6ac27bef99460d250c2e62bd3d9c5b
|
@@ -0,0 +1,36 @@
|
|
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
|
+
matrix:
|
23
|
+
ruby-version: ['2.7', '3.0', '3.1']
|
24
|
+
|
25
|
+
steps:
|
26
|
+
- uses: actions/checkout@v2
|
27
|
+
- name: Set up Ruby
|
28
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
29
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
30
|
+
# uses: ruby/setup-ruby@v1
|
31
|
+
uses: ruby/setup-ruby@f0971f0dd45a5cbb3f119f7db77cc58057c53530
|
32
|
+
with:
|
33
|
+
ruby-version: ${{ matrix.ruby-version }}
|
34
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
35
|
+
- name: Run tests
|
36
|
+
run: bundle exec rake
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.5
|
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.0.2
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
## [1.1.0] - 202
|
2
|
+
* Specify UTF-8 encoding for XML encoding (#35 via @sh1nduu)
|
3
|
+
* Added GeoJSON conversion (#38 via @tyrauber and @niborg)
|
4
|
+
* Support Ruby 3 (#43 via @LocoDelAssembly)
|
5
|
+
* Fix nil-to-Time comparison (#46 via @frodrigo)
|
6
|
+
* Fix bug when <rte> GPX file does not specify <name> tag (#41 via @niborg)
|
7
|
+
* Drop Ruby 2.5 and 2.6 from CI (#50 via @niborg)
|
8
|
+
## [1.0.0] - 2018-03-06
|
9
|
+
|
10
|
+
* Fix duplication of points on appending segment to track (#20 via @niborg)
|
11
|
+
* Remove pythagorean distance (#28 fixing #27, via @moveson)
|
12
|
+
* Ignore empty segments (#29 via @nathanvda)
|
13
|
+
* Introduce Rubocop (#31)
|
14
|
+
* Explicit test support for Ruby 2.5 (#30)
|
15
|
+
|
1
16
|
## [0.9.0] - 2017-01-05
|
2
17
|
|
3
18
|
* Upgrade Nokogiri deps to be more explicit, then explicitly bump the Ruby
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -10,15 +10,19 @@ the data as objects. For more info on the GPX format, see
|
|
10
10
|
http://www.topografix.com/gpx.asp.
|
11
11
|
|
12
12
|
In addition to parsing GPX files, this library is capable of converting
|
13
|
-
Magellan NMEA files to GPX,
|
14
|
-
|
15
|
-
the tracks and points in a file (such as distance, duration, average speed,
|
16
|
-
etc).
|
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).
|
17
16
|
|
18
17
|
## Requirements
|
19
18
|
|
20
|
-
As of `0.
|
19
|
+
As of `1.0.0`, `gpx` requires at least Ruby 2.2 to run.
|
21
20
|
|
21
|
+
## Installation
|
22
|
+
Add to your gemfile:
|
23
|
+
```
|
24
|
+
gem 'gpx'
|
25
|
+
```
|
22
26
|
## Examples
|
23
27
|
|
24
28
|
Reading a GPX file, and cropping its contents to a given area:
|
@@ -37,6 +41,17 @@ if GPX::MagellanTrackLog::is_magellan_file?(filename)
|
|
37
41
|
end
|
38
42
|
```
|
39
43
|
|
44
|
+
Converting GeoJSON data to GPX can be achieved by providing a
|
45
|
+
file path, file, or the data in string format:
|
46
|
+
```ruby
|
47
|
+
# Converting from a file name
|
48
|
+
gpx_file = GPX::GeoJSON.convert_to_gpx(geojson_file: 'mygeojsonfile.json')
|
49
|
+
|
50
|
+
# Converting from a string
|
51
|
+
data = JSON.generate(my_geojson_hash)
|
52
|
+
gpx_file = GPX::GeoJSON.convert_to_gpx(geojson_data: data)
|
53
|
+
```
|
54
|
+
|
40
55
|
Exporting an ActiveRecord to GPXFile (as Waypoints)
|
41
56
|
```ruby
|
42
57
|
#
|
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/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,26 +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.'
|
13
14
|
|
14
|
-
s.required_ruby_version = '
|
15
|
+
s.required_ruby_version = '>= 2.5', '< 4'
|
15
16
|
|
16
|
-
s.files = `git ls-files`.split(
|
17
|
+
s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
17
18
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
18
|
-
s.require_paths = [
|
19
|
-
s.has_rdoc = true
|
19
|
+
s.require_paths = ['lib']
|
20
20
|
|
21
|
-
s.homepage =
|
22
|
-
s.add_dependency 'rake'
|
21
|
+
s.homepage = 'http://www.github.com/dougfales/gpx'
|
23
22
|
s.add_dependency 'nokogiri', '~>1.7'
|
23
|
+
s.add_dependency 'rake'
|
24
24
|
s.add_development_dependency 'bundler'
|
25
25
|
s.add_development_dependency 'minitest'
|
26
|
+
s.add_development_dependency 'rubocop'
|
26
27
|
end
|
data/lib/gpx/bounds.rb
CHANGED
@@ -1,58 +1,41 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
#
|
4
|
-
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
-
# a copy of this software and associated documentation files (the
|
6
|
-
# "Software"), to deal in the Software without restriction, including
|
7
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
-
# the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be
|
13
|
-
# included in all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
-
#++
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
23
3
|
module GPX
|
24
4
|
class Bounds < Base
|
25
|
-
attr_accessor :min_lat, :max_lat, :max_lon, :min_lon
|
5
|
+
attr_accessor :min_lat, :max_lat, :max_lon, :min_lon
|
26
6
|
|
27
7
|
# Creates a new bounds object with the passed-in min and max longitudes
|
28
8
|
# and latitudes.
|
29
|
-
def initialize(opts = { :
|
30
|
-
|
31
|
-
@
|
9
|
+
def initialize(opts = { min_lat: 90.0, max_lat: -90.0, min_lon: 180.0, max_lon: -180.0 })
|
10
|
+
super()
|
11
|
+
@min_lat = opts[:min_lat].to_f
|
12
|
+
@max_lat = opts[:max_lat].to_f
|
13
|
+
@min_lon = opts[:min_lon].to_f
|
14
|
+
@max_lon = opts[:max_lon].to_f
|
32
15
|
end
|
33
16
|
|
34
17
|
# Returns the middle latitude.
|
35
18
|
def center_lat
|
36
|
-
distance = (max_lat - min_lat)/2.0
|
19
|
+
distance = (max_lat - min_lat) / 2.0
|
37
20
|
(min_lat + distance)
|
38
21
|
end
|
39
22
|
|
40
23
|
# Returns the middle longitude.
|
41
24
|
def center_lon
|
42
|
-
distance = (max_lon - min_lon)/2.0
|
25
|
+
distance = (max_lon - min_lon) / 2.0
|
43
26
|
(min_lon + distance)
|
44
27
|
end
|
45
28
|
|
46
29
|
# Returns true if the pt is within these bounds.
|
47
30
|
def contains?(pt)
|
48
|
-
(pt.lat >=
|
31
|
+
((pt.lat >= min_lat) && (pt.lat <= max_lat) && (pt.lon >= min_lon) && (pt.lon <= max_lon))
|
49
32
|
end
|
50
33
|
|
51
34
|
# Adds an item to itself, expanding its min/max lat/lon as needed to
|
52
35
|
# contain the given item. The item can be either another instance of
|
53
36
|
# Bounds or a Point.
|
54
37
|
def add(item)
|
55
|
-
if
|
38
|
+
if item.respond_to?(:lat) && item.respond_to?(:lon)
|
56
39
|
@min_lat = item.lat if item.lat < @min_lat
|
57
40
|
@min_lon = item.lon if item.lon < @min_lon
|
58
41
|
@max_lat = item.lat if item.lat > @max_lat
|
@@ -69,6 +52,5 @@ module GPX
|
|
69
52
|
def to_s
|
70
53
|
"min_lat: #{min_lat} min_lon: #{min_lon} max_lat: #{max_lat} max_lon: #{max_lon}"
|
71
54
|
end
|
72
|
-
|
73
55
|
end
|
74
56
|
end
|