simple-trail 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1fa2ce5f20ed11b5c661b3af58649fc5bafc6d30b2e17d72fff9be7eb5191d69
4
- data.tar.gz: 8ca3ab027c0902e97b9af1c1caa79830c7eb4df5198fbe986da71d30af0f4de3
3
+ metadata.gz: aba06ca65c57e7950b28e45822dcddaa944b6375eb6e8d1ceedaee8031f1e163
4
+ data.tar.gz: 3b82b1e9d848442630deaa9b09ea4fa02c51dce42cf86a980d1abb823746a82e
5
5
  SHA512:
6
- metadata.gz: 6a2825513f6510c2a0de740f3ae4b3ef56177bf3c8c7db9cdf80bb5f022176e7709069333d5b036d38eb4c6be5854121247846ea09a6038d06a28f7c57ad0ba3
7
- data.tar.gz: 01ad5f7cd8e321e6ba8db7ed26d062a6a60e38650e3ebcc34c2b792a7fbfdffc4cb250da73501ac558503b853fb688eaef0c339dfe4d67dba877679134fda1de
6
+ metadata.gz: 40c43bd89ba95b26820580c88afbd6b327fac9c1edb4ab42a38441703d1d93be7c3f5cf33a9ee9fe99848875030a2de788a55c14db4c8fd7483090f154c7bd72
7
+ data.tar.gz: 98cd69d440cd930578cea1ebc9b0240f885fa508f62860e7acd75668a89b2e692304e8d5cc90720818b71dcb1bcaa6c5d5ca9abb0892b98c0ea79e3f9b2533c7
@@ -0,0 +1,29 @@
1
+ require 'nokogiri'
2
+
3
+ module Generator
4
+ class Gpx
5
+ attr_reader :output
6
+
7
+ def initialize(points:, name: 'GPX file')
8
+ @points = points
9
+ @name = name
10
+ end
11
+
12
+ def gpx
13
+ builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
14
+ xml.gpx(version: '1.0') {
15
+ xml.name { @name }
16
+ xml.trk {
17
+ xml.trkseg {
18
+ @points.map do |point|
19
+ xml.trkpt(lat: point[:lat], lon: point[:lon])
20
+ end
21
+ }
22
+ }
23
+ }
24
+ end
25
+
26
+ @output = builder.to_xml
27
+ end
28
+ end
29
+ end
@@ -4,8 +4,9 @@ module Manipulation
4
4
  class Enricher
5
5
  attr_reader :enriched_points
6
6
 
7
- def initialize(points)
7
+ def initialize(points, distance_limit=nil)
8
8
  @points = points
9
+ @distance_limit = distance_limit
9
10
  @counter = 3
10
11
  end
11
12
 
@@ -31,7 +32,8 @@ module Manipulation
31
32
  offset = 0
32
33
  @gaps.each do |gap|
33
34
  middle_point = calculate_middle_point(@points[gap[:origin] + offset], @points[gap[:destination] + offset])
34
- @points = @points.insert(gap[:destination] + offset, {lat: middle_point.lat, lon: middle_point.lng })
35
+ est_elevation = (@points[gap[:origin] + offset][:ele].to_f + @points[gap[:destination] + offset][:ele].to_f) / 2.0
36
+ @points = @points.insert(gap[:destination] + offset, {lat: middle_point.lat, lon: middle_point.lng, ele: est_elevation })
35
37
 
36
38
  offset += 1
37
39
  end
@@ -43,12 +45,12 @@ module Manipulation
43
45
  latlan(loc1).midpoint_to(latlan(loc2))
44
46
  end
45
47
 
46
- GAP_LIMIT = 0.075
47
48
  def detect_gaps
49
+ gap_limit = @distance_limit || 0.1
48
50
  @gaps = []
49
51
  @points.each_cons(2).with_index do |pair, i|
50
52
  distance = calculate_distance(pair[0], pair[1])
51
- @gaps << {origin: i, destination: i+1, distance: distance} if distance > GAP_LIMIT
53
+ @gaps << {origin: i, destination: i+1, distance: distance} if distance > gap_limit
52
54
  end
53
55
  end
54
56
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Parser
4
4
  class Gpx
5
- attr_reader :simplified_points, :points, :parsed_file
5
+ attr_reader :simplified_points, :points, :points_of_interests, :parsed_file
6
6
 
7
7
  def initialize(filename)
8
8
  @filename = filename
@@ -13,6 +13,7 @@ module Parser
13
13
  @parsed_file = XmlHasher.parse(file)[:gpx]
14
14
  fail unless @parsed_file
15
15
  extract_points
16
+ extract_pois
16
17
  end
17
18
 
18
19
  def meta
@@ -27,6 +28,10 @@ module Parser
27
28
  @simplified_points = @points.map { |point| point.select { |key, _| [:lon, :lat].include? key } }
28
29
  end
29
30
 
31
+ def extract_pois
32
+ @points_of_interests = @parsed_file[:wpt]
33
+ end
34
+
30
35
  def extract_data
31
36
  metadata = @parsed_file[:metadata]
32
37
  {
data/lib/simple_trail.rb CHANGED
@@ -8,6 +8,7 @@ require File.expand_path('simple_trail/manipulation/statistics', __dir__)
8
8
  require File.expand_path('simple_trail/manipulation/straightener', __dir__)
9
9
  require File.expand_path('simple_trail/manipulation/unifier', __dir__)
10
10
  require File.expand_path('simple_trail/manipulation/enricher', __dir__)
11
+ require File.expand_path('simple_trail/generator/gpx', __dir__)
11
12
 
12
13
  module SimpleTrail
13
14
  Geokit.default_units = :kms
data/simple-trail.gemspec CHANGED
@@ -5,7 +5,7 @@ $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.1.0'
8
+ s.version = '0.2.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'
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.license = 'MIT'
19
19
  s.add_dependency 'geokit', '1.13'
20
20
  s.add_dependency 'xmlhasher', '~> 1.0'
21
+ s.add_dependency 'nokogiri', '~> 1.13'
21
22
  s.add_development_dependency 'pry', '~> 0.13'
22
23
  s.add_development_dependency 'rspec', '~> 3.9'
23
24
  end