simple-trail 0.2.5 → 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/lib/simple_trail/manipulation/enricher.rb +3 -2
- data/lib/simple_trail/parser/base.rb +26 -0
- data/lib/simple_trail/parser/extract_points.rb +18 -0
- data/lib/simple_trail/parser/gpx.rb +1 -21
- data/lib/simple_trail/parser/gpx_string.rb +21 -0
- data/lib/simple_trail.rb +3 -0
- data/simple-trail.gemspec +2 -1
- data/spec/parser/gpx_string_spec.rb +37 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ec7ad04579f7af6e5c6df0517ee1f8ef8ba986f8895ce92e7548fddec91dabe
|
4
|
+
data.tar.gz: 694d57d1ec75c501e48e93acbdaad27d63dda944671323666d045c47031b4e77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b18740f2f648846202cf58a00f9a1debdae27273cd769bb401b27752d6c6c5b6b6f514445573c57fc3da650fea96827bd75e2146ff5539e8c5c78ca1b4b0861e
|
7
|
+
data.tar.gz: 0d1fe7392d9c8701da42433b52ed498e0a959371d405f3dcc8aa4d632af56df28a2cc305f6ef5c6aa9717ce0719b36cc73663e0635922a1e6ee7ccddf6973904
|
@@ -75,11 +75,12 @@ module Manipulation
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def add_km_markers
|
78
|
-
total_distance = @points[-1][:total_distance].floor
|
78
|
+
total_distance = @points[-1][:total_distance].floor
|
79
79
|
start_v = @offset.to_f.ceil
|
80
80
|
|
81
81
|
(start_v..start_v+total_distance).each do |i|
|
82
|
-
|
82
|
+
next if i == @offset.to_f
|
83
|
+
find_and_enrich_first_occurence(i)
|
83
84
|
end
|
84
85
|
end
|
85
86
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Parser
|
3
|
+
class Base
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def extract_points
|
8
|
+
points_reader = ExtractPoints.new(@parsed_file)
|
9
|
+
points_reader.read_points
|
10
|
+
@points = points_reader.points
|
11
|
+
@simplified_points = points_reader.simplified_points
|
12
|
+
end
|
13
|
+
|
14
|
+
def extract_pois
|
15
|
+
@points_of_interests = @parsed_file[:wpt]
|
16
|
+
end
|
17
|
+
|
18
|
+
def extract_data
|
19
|
+
metadata = @parsed_file[:metadata]
|
20
|
+
{
|
21
|
+
name: metadata[:name],
|
22
|
+
author: metadata[:author][:name]
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Parser
|
4
|
+
class ExtractPoints
|
5
|
+
attr_reader :simplified_points, :points
|
6
|
+
|
7
|
+
def initialize(parsed_file)
|
8
|
+
@parsed_file = parsed_file
|
9
|
+
end
|
10
|
+
|
11
|
+
def read_points
|
12
|
+
segments = @parsed_file.dig(:trk, :trkseg)
|
13
|
+
@points = segments.is_a?(Array) ? segments.map { |seg| seg[:trkpt] }.flatten : segments[:trkpt]
|
14
|
+
@simplified_points = @points.map { |point| point.select { |key, _| [:lon, :lat].include? key } }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Parser
|
4
|
-
class Gpx
|
4
|
+
class Gpx < Base
|
5
5
|
attr_reader :simplified_points, :points, :points_of_interests, :parsed_file
|
6
6
|
|
7
7
|
def initialize(filename)
|
@@ -19,25 +19,5 @@ module Parser
|
|
19
19
|
def meta
|
20
20
|
@meta ||= extract_data
|
21
21
|
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def extract_points
|
26
|
-
segments = @parsed_file.dig(:trk, :trkseg)
|
27
|
-
@points = segments.is_a?(Array) ? segments.map { |seg| seg[:trkpt] }.flatten : segments[:trkpt]
|
28
|
-
@simplified_points = @points.map { |point| point.select { |key, _| [:lon, :lat].include? key } }
|
29
|
-
end
|
30
|
-
|
31
|
-
def extract_pois
|
32
|
-
@points_of_interests = @parsed_file[:wpt]
|
33
|
-
end
|
34
|
-
|
35
|
-
def extract_data
|
36
|
-
metadata = @parsed_file[:metadata]
|
37
|
-
{
|
38
|
-
name: metadata[:name],
|
39
|
-
author: metadata[:author][:name]
|
40
|
-
}
|
41
|
-
end
|
42
22
|
end
|
43
23
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Parser
|
3
|
+
class GpxString < Base
|
4
|
+
attr_reader :simplified_points, :points, :points_of_interests, :parsed_file
|
5
|
+
|
6
|
+
def initialize(file_content)
|
7
|
+
@file_content = file_content
|
8
|
+
end
|
9
|
+
|
10
|
+
def read
|
11
|
+
@parsed_file = XmlHasher.parse(@file_content)[:gpx]
|
12
|
+
fail unless @parsed_file
|
13
|
+
extract_points
|
14
|
+
extract_pois
|
15
|
+
end
|
16
|
+
|
17
|
+
def meta
|
18
|
+
@meta ||= extract_data
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/simple_trail.rb
CHANGED
@@ -3,7 +3,10 @@
|
|
3
3
|
require 'geokit'
|
4
4
|
require 'xmlhasher'
|
5
5
|
|
6
|
+
require File.expand_path('simple_trail/parser/base', __dir__)
|
6
7
|
require File.expand_path('simple_trail/parser/gpx', __dir__)
|
8
|
+
require File.expand_path('simple_trail/parser/gpx_string', __dir__)
|
9
|
+
require File.expand_path('simple_trail/parser/extract_points', __dir__)
|
7
10
|
require File.expand_path('simple_trail/manipulation/statistics', __dir__)
|
8
11
|
require File.expand_path('simple_trail/manipulation/straightener', __dir__)
|
9
12
|
require File.expand_path('simple_trail/manipulation/unifier', __dir__)
|
data/simple-trail.gemspec
CHANGED
@@ -5,12 +5,13 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = 'simple-trail'
|
8
|
-
s.version = '0.
|
8
|
+
s.version = '0.3.0'
|
9
9
|
s.date = '2020-08-03'
|
10
10
|
s.summary = 'Readind and manipulating GPX and other trail representation file'
|
11
11
|
s.description = 'Optimazing and manipulating GPX file data. For my private purposes mostly'
|
12
12
|
s.authors = ['Staszek Zawadzki']
|
13
13
|
s.email = 'st.zawadzki@gmail.com'
|
14
|
+
s.homepage = 'https://github.com/PadawanBreslau/simple-trail'
|
14
15
|
|
15
16
|
s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
16
17
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Parser::GpxString do
|
6
|
+
it 'reads the file' do
|
7
|
+
gpx_parser = described_class.new(File.new('./spec/examples/test_1.gpx').read)
|
8
|
+
expect { gpx_parser.read }.not_to raise_error
|
9
|
+
expect(gpx_parser.parsed_file).not_to be_nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'reads metadata' do
|
13
|
+
gpx_parser = described_class.new(File.new('./spec/examples/test_1.gpx').read)
|
14
|
+
gpx_parser.read
|
15
|
+
|
16
|
+
expect(gpx_parser.meta[:author]).to eq 'choosen'
|
17
|
+
expect(gpx_parser.meta[:name]).to eq '06.06.2020 18:56'
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'reads points simplified/all' do
|
21
|
+
gpx_parser = described_class.new(File.new('./spec/examples/test_1.gpx').read)
|
22
|
+
gpx_parser.read
|
23
|
+
expect(gpx_parser.points.size).to eq 190
|
24
|
+
expect(gpx_parser.points.size).to eq gpx_parser.simplified_points.size
|
25
|
+
|
26
|
+
random_index = rand(gpx_parser.points.size)
|
27
|
+
expect(gpx_parser.points[random_index][:lat]).to eq gpx_parser.simplified_points[random_index][:lat]
|
28
|
+
expect(gpx_parser.points[random_index][:lon]).to eq gpx_parser.simplified_points[random_index][:lon]
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'reads file with segments' do
|
32
|
+
gpx_parser = described_class.new(File.new('./spec/examples/test_with_segments.gpx').read)
|
33
|
+
expect { gpx_parser.read }.not_to raise_error
|
34
|
+
|
35
|
+
expect(gpx_parser.points.size).to eq 355
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple-trail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Staszek Zawadzki
|
@@ -96,7 +96,10 @@ files:
|
|
96
96
|
- lib/simple_trail/manipulation/statistics.rb
|
97
97
|
- lib/simple_trail/manipulation/straightener.rb
|
98
98
|
- lib/simple_trail/manipulation/unifier.rb
|
99
|
+
- lib/simple_trail/parser/base.rb
|
100
|
+
- lib/simple_trail/parser/extract_points.rb
|
99
101
|
- lib/simple_trail/parser/gpx.rb
|
102
|
+
- lib/simple_trail/parser/gpx_string.rb
|
100
103
|
- simple-trail.gemspec
|
101
104
|
- spec/examples/gss20-full-official.gpx
|
102
105
|
- spec/examples/kbl.gpx
|
@@ -124,8 +127,9 @@ files:
|
|
124
127
|
- spec/manipulation/unifier_spec.rb
|
125
128
|
- spec/parser/gpx_poi_spec.rb
|
126
129
|
- spec/parser/gpx_spec.rb
|
130
|
+
- spec/parser/gpx_string_spec.rb
|
127
131
|
- spec/spec_helper.rb
|
128
|
-
homepage:
|
132
|
+
homepage: https://github.com/PadawanBreslau/simple-trail
|
129
133
|
licenses:
|
130
134
|
- MIT
|
131
135
|
metadata: {}
|
@@ -175,4 +179,5 @@ test_files:
|
|
175
179
|
- spec/manipulation/unifier_spec.rb
|
176
180
|
- spec/parser/gpx_poi_spec.rb
|
177
181
|
- spec/parser/gpx_spec.rb
|
182
|
+
- spec/parser/gpx_string_spec.rb
|
178
183
|
- spec/spec_helper.rb
|