jeti-log 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: 38361a302d8cd7e19d45e89e48e8d5af3f686a41
4
- data.tar.gz: 7deb13061c54865fe749dd77228da253e5b8078a
3
+ metadata.gz: 158deb9294114c12180cf33b96f0647c6d17caf3
4
+ data.tar.gz: c55a6188529118570b4e1e2e7a0abe9d2c104fa9
5
5
  SHA512:
6
- metadata.gz: 84298116c3e25340210dbeff80248da90d3f599a70a87df7fa52f89de1b6c54060af4b4ca8451a7a92694cdd6ba908d433116381e89333e0413249657b4c77c3
7
- data.tar.gz: 83f65303d59422265e7564ec15b803552a034a0b2104f1f66bfa2ac67d95c1fddcf450f15d8e8bdf828588838c21344d4634a6fc0788fe3c6bbf35b801b12843
6
+ metadata.gz: ee311d71497959b42d29dc478ea3401b01a44617fdbbcf9fed02dbbc18fff4d7c8c703f8d9cdee2668d68686034323762fe570ec3178492d004233a3ec24732d
7
+ data.tar.gz: 2d6a18756da1256761b7fc24d65f1f9a614d09b13a828c225b32b22f36023bac0d71e5e95d8fc910e4678311a8ba80e1715460cc88f5038de99793a90083a9af
data/lib/jeti/log/file.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'open-uri'
2
+ require 'ruby_kml'
2
3
 
3
4
  module Jeti; module Log;
4
5
 
@@ -94,8 +95,98 @@ module Jeti; module Log;
94
95
  @mgps_locations ||= build_mgps_locations
95
96
  end
96
97
 
98
+ # Determines if KML methods can be called for this session.
99
+ #
100
+ # @return [Boolean] true if KML can be generated for this session, false otherwise
101
+ def to_kml?
102
+ mgps_locations?
103
+ end
104
+
105
+ # Converts the session into a KML document containing a placemark.
106
+ #
107
+ # @param file_options [Hash] hash containing options for file
108
+ # @param placemark_options [Hash] hash containing options for placemark
109
+ # @return [String] KML document for the session
110
+ # @see #to_kml_file file options
111
+ # @see #to_kml_placemark placemark options
112
+ def to_kml(file_options = {}, placemark_options = {})
113
+ raise RuntimeError, 'No coordinates available for KML generation' unless to_kml?
114
+ to_kml_file(file_options, placemark_options).render
115
+ end
116
+
117
+ # Converts the session into a KMLFile containing a placemark.
118
+ #
119
+ # @param file_options [Hash] hash containing options for file
120
+ # @option file_options [String] :name name option of KML::Document
121
+ # @option file_options [String] :description name option of KML::Document
122
+ # @option file_options [String] :style_id id option of KML::Style
123
+ # @param placemark_options [Hash] hash containing options for placemark
124
+ # @return [KMLFile] file for the session
125
+ # @see #to_kml_placemark placemark options
126
+ def to_kml_file(file_options = {}, placemark_options = {})
127
+ raise RuntimeError, 'No coordinates available for KML generation' unless to_kml?
128
+ options = apply_default_file_options(file_options)
129
+
130
+ kml = KMLFile.new
131
+ kml.objects << KML::Document.new(
132
+ :name => options[:name],
133
+ :description => options[:description],
134
+ :styles => [
135
+ KML::Style.new(
136
+ :id => options[:style_id],
137
+ :line_style => KML::LineStyle.new(:color => '7F00FFFF', :width => 4),
138
+ :poly_style => KML::PolyStyle.new(:color => '7F00FF00')
139
+ )
140
+ ],
141
+ :features => [ to_kml_placemark(placemark_options) ]
142
+ )
143
+ kml
144
+ end
145
+
146
+ # Converts the session into a KML::Placemark containing GPS coordinates.
147
+ #
148
+ # @param options [Hash] hash containing options for placemark
149
+ # @option options [String] :altitude_mode altitude_mode option of KML::LineString
150
+ # @option options [Boolean] :extrude extrude option of KML::LineString
151
+ # @option options [String] :name name option of KML::Placemark
152
+ # @option options [String] :style_url style_url option of KML::Placemark
153
+ # @option options [Boolean] :tessellate tessellate option of KML::LineString
154
+ # @return [KML::Placemark] placemark for the session
155
+ def to_kml_placemark(options = {})
156
+ raise RuntimeError, 'No coordinates available for KML generation' unless to_kml?
157
+ options = apply_default_placemark_options(options)
158
+
159
+ coords = mgps_locations.map { |l| [l[1][:longitude], l[1][:latitude], l[1][:altitude]] }
160
+ KML::Placemark.new(
161
+ :name => options[:name],
162
+ :style_url => options[:style_url],
163
+ :geometry => KML::LineString.new(
164
+ :altitude_mode => options[:altitude_mode],
165
+ :extrude => options[:extrude],
166
+ :tessellate => options[:tessellate],
167
+ :coordinates => coords.map { |c| c.join(',') }.join(' ')
168
+ )
169
+ )
170
+ end
171
+
97
172
  private
98
173
 
174
+ def apply_default_file_options options
175
+ options = { :name => 'Jeti MGPS Path' }.merge(options)
176
+ options = { :description => 'Session paths for GPS log data' }.merge(options)
177
+ options = { :style_id => 'default-poly-style' }.merge(options)
178
+ options
179
+ end
180
+
181
+ def apply_default_placemark_options options
182
+ options = { :altitude_mode => 'absolute' }.merge(options)
183
+ options = { :extrude => true }.merge(options)
184
+ options = { :name => "Session (#{duration.round(1)}s)" }.merge(options)
185
+ options = { :style_url => '#default-poly-style' }.merge(options)
186
+ options = { :tessellate => true }.merge(options)
187
+ options
188
+ end
189
+
99
190
  def build_mgps_locations
100
191
  lats = build_value_dataset('MGPS', 'Latitude')
101
192
  lons = build_value_dataset('MGPS', 'Longitude')
@@ -1,5 +1,5 @@
1
1
  module Jeti
2
2
  module Log
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
data/spec/file_spec.rb CHANGED
@@ -52,6 +52,14 @@ describe Jeti::Log::File do
52
52
 
53
53
  its(:mgps_locations?) { should be_false }
54
54
 
55
+ its(:to_kml?) { should be_false }
56
+
57
+ specify { expect { subject.to_kml }.to raise_error }
58
+
59
+ specify { expect { subject.to_kml_file }.to raise_error }
60
+
61
+ specify { expect { subject.to_kml_placemark }.to raise_error }
62
+
55
63
  end
56
64
 
57
65
  context 'with data file gps-crash.log' do
@@ -129,6 +137,20 @@ describe Jeti::Log::File do
129
137
  expect(loc[1][:course]).to eql(0)
130
138
  end
131
139
 
140
+ its(:to_kml?) { should be_true }
141
+
142
+ its(:to_kml) { should be_a(String) }
143
+
144
+ its(:to_kml_file) { should be_a(KMLFile) }
145
+
146
+ it 'should take options for file and placemark' do
147
+ kml = subject.to_kml_file({ :name => 'File Name' }, { :name => 'Placemark Name' })
148
+ kml.objects[0].name.should eql('File Name')
149
+ kml.objects[0].features[0].name.should eql('Placemark Name')
150
+ end
151
+
152
+ its(:to_kml_placemark) { should be_a(KML::Placemark) }
153
+
132
154
  end
133
155
 
134
156
  it 'should raise for invalid or missing files' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jeti-log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Veys