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 +4 -4
- data/lib/jeti/log/file.rb +91 -0
- data/lib/jeti/log/version.rb +1 -1
- data/spec/file_spec.rb +22 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 158deb9294114c12180cf33b96f0647c6d17caf3
|
4
|
+
data.tar.gz: c55a6188529118570b4e1e2e7a0abe9d2c104fa9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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')
|
data/lib/jeti/log/version.rb
CHANGED
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
|