epic-geo 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.travis.yml +6 -0
- data/Gemfile +6 -0
- data/LICENSE +21 -0
- data/README.md +25 -0
- data/Rakefile +5 -0
- data/coverage/.last_run.json +5 -0
- data/coverage/.resultset.json +326 -0
- data/epic-geo.gemspec +32 -0
- data/lib/epic-geo.rb +11 -0
- data/lib/geojson/write_geojson_featurecollection.rb +53 -0
- data/lib/kml/kml_style_helper.rb +150 -0
- data/lib/kml/kml_writer.rb +97 -0
- data/spec/geojson_spec.rb +1 -0
- data/spec/kml_spec.rb +19 -0
- data/spec/spec_helper.rb +24 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ecca0c0c284b58252bc766c0b3f809da41730807
|
4
|
+
data.tar.gz: 7708f3e3be966206b68c3efbb3fe116affa724b8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: af449ddca054a06294976344a8cd7d3a95fb18bb4e8f2d4a611ec0848f0b4a830f3d323a414de6b97c558499205e3220bcd673d9e74e35c61fee53a7ee13dc15
|
7
|
+
data.tar.gz: a42c0d3b6473bc9006619b0f36ea948e9e22eb680988d08ab5f0187413f6b66c281473064df3936c8437f19554bd4d45e24c373dc43735f8bb60906aafc42d78
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Jennings Anderson
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Epic Geo
|
2
|
+
========
|
3
|
+
[](http://badge.fury.io/rb/epic-geo)
|
4
|
+
[](https://travis-ci.org/jenningsanderson/epic-geo)
|
5
|
+
[](https://coveralls.io/r/jenningsanderson/epic-geo)
|
6
|
+
|
7
|
+
####Background
|
8
|
+
A gem for interfacing with both twitter and OSM data for Project EPIC at University of Colorado Boulder.
|
9
|
+
|
10
|
+
####Dependencies
|
11
|
+
Most of the functionality within this gem requires access to project EPIC's NoSQL Mongo database. This will require being on campus or the connected via VPN.
|
12
|
+
|
13
|
+
**Gem Dependencies**
|
14
|
+
- ```rgeo``` - A decently maintained geospatial gem for Ruby. Allows for easy geospatial calculations such as area and length.
|
15
|
+
|
16
|
+
- ```georuby``` - Another geospatial library for Ruby which offers support for reading and writing shapefiles.
|
17
|
+
- ```geo_ruby/kml``` is also currently required.
|
18
|
+
|
19
|
+
###Installation
|
20
|
+
(Recommended) Pull the latest version of the gem from github:
|
21
|
+
1. Put the following line in your Gemfile: ```gem 'epic-geo', github: 'jenningsanderson/epic-geo'```
|
22
|
+
2. Run ```bundle install```
|
23
|
+
|
24
|
+
Via RubyGems (Latest stable build):
|
25
|
+
```gem install epic-geo```
|
data/Rakefile
ADDED
@@ -0,0 +1,326 @@
|
|
1
|
+
{
|
2
|
+
"RSpec": {
|
3
|
+
"coverage": {
|
4
|
+
"/Users/jenningsanderson/Documents/epic-geo/lib/epic-geo.rb": [
|
5
|
+
null,
|
6
|
+
1,
|
7
|
+
null,
|
8
|
+
null,
|
9
|
+
1,
|
10
|
+
1,
|
11
|
+
null,
|
12
|
+
1,
|
13
|
+
0,
|
14
|
+
null,
|
15
|
+
null
|
16
|
+
],
|
17
|
+
"/Users/jenningsanderson/Documents/epic-geo/lib/kml/kml_writer.rb": [
|
18
|
+
1,
|
19
|
+
1,
|
20
|
+
1,
|
21
|
+
null,
|
22
|
+
null,
|
23
|
+
null,
|
24
|
+
null,
|
25
|
+
null,
|
26
|
+
1,
|
27
|
+
null,
|
28
|
+
1,
|
29
|
+
null,
|
30
|
+
1,
|
31
|
+
null,
|
32
|
+
1,
|
33
|
+
1,
|
34
|
+
1,
|
35
|
+
1,
|
36
|
+
null,
|
37
|
+
1,
|
38
|
+
null,
|
39
|
+
null,
|
40
|
+
null,
|
41
|
+
1,
|
42
|
+
0,
|
43
|
+
0,
|
44
|
+
0,
|
45
|
+
null,
|
46
|
+
null,
|
47
|
+
null,
|
48
|
+
1,
|
49
|
+
0,
|
50
|
+
null,
|
51
|
+
0,
|
52
|
+
0,
|
53
|
+
0,
|
54
|
+
null,
|
55
|
+
null,
|
56
|
+
0,
|
57
|
+
0,
|
58
|
+
0,
|
59
|
+
null,
|
60
|
+
null,
|
61
|
+
null,
|
62
|
+
0,
|
63
|
+
null,
|
64
|
+
null,
|
65
|
+
null,
|
66
|
+
1,
|
67
|
+
0,
|
68
|
+
0,
|
69
|
+
0,
|
70
|
+
null,
|
71
|
+
0,
|
72
|
+
0,
|
73
|
+
null,
|
74
|
+
0,
|
75
|
+
0,
|
76
|
+
0,
|
77
|
+
0,
|
78
|
+
null,
|
79
|
+
0,
|
80
|
+
null,
|
81
|
+
0,
|
82
|
+
0,
|
83
|
+
0,
|
84
|
+
null,
|
85
|
+
0,
|
86
|
+
null,
|
87
|
+
null,
|
88
|
+
0,
|
89
|
+
0,
|
90
|
+
0,
|
91
|
+
0,
|
92
|
+
null,
|
93
|
+
0,
|
94
|
+
0,
|
95
|
+
null,
|
96
|
+
null,
|
97
|
+
null,
|
98
|
+
null,
|
99
|
+
null,
|
100
|
+
null,
|
101
|
+
null,
|
102
|
+
null,
|
103
|
+
0,
|
104
|
+
0,
|
105
|
+
null,
|
106
|
+
0,
|
107
|
+
null,
|
108
|
+
null,
|
109
|
+
null,
|
110
|
+
1,
|
111
|
+
0,
|
112
|
+
null,
|
113
|
+
null,
|
114
|
+
null
|
115
|
+
],
|
116
|
+
"/Users/jenningsanderson/Documents/epic-geo/lib/kml/kml_style_helper.rb": [
|
117
|
+
1,
|
118
|
+
0,
|
119
|
+
0,
|
120
|
+
0,
|
121
|
+
0,
|
122
|
+
0,
|
123
|
+
null,
|
124
|
+
0,
|
125
|
+
null,
|
126
|
+
null,
|
127
|
+
1,
|
128
|
+
0,
|
129
|
+
null,
|
130
|
+
null,
|
131
|
+
1,
|
132
|
+
null,
|
133
|
+
null,
|
134
|
+
0,
|
135
|
+
0,
|
136
|
+
null,
|
137
|
+
0,
|
138
|
+
0,
|
139
|
+
0,
|
140
|
+
0,
|
141
|
+
0,
|
142
|
+
0,
|
143
|
+
null,
|
144
|
+
0,
|
145
|
+
null,
|
146
|
+
null,
|
147
|
+
0,
|
148
|
+
0,
|
149
|
+
null,
|
150
|
+
null,
|
151
|
+
null,
|
152
|
+
null,
|
153
|
+
null,
|
154
|
+
0,
|
155
|
+
null,
|
156
|
+
null,
|
157
|
+
null,
|
158
|
+
null,
|
159
|
+
null,
|
160
|
+
null,
|
161
|
+
null,
|
162
|
+
null,
|
163
|
+
null,
|
164
|
+
0,
|
165
|
+
null,
|
166
|
+
null,
|
167
|
+
null,
|
168
|
+
null,
|
169
|
+
null,
|
170
|
+
0,
|
171
|
+
null,
|
172
|
+
null,
|
173
|
+
null,
|
174
|
+
null,
|
175
|
+
null,
|
176
|
+
null,
|
177
|
+
0,
|
178
|
+
null,
|
179
|
+
null,
|
180
|
+
null,
|
181
|
+
1,
|
182
|
+
0,
|
183
|
+
null,
|
184
|
+
0,
|
185
|
+
null,
|
186
|
+
null,
|
187
|
+
0,
|
188
|
+
null,
|
189
|
+
null,
|
190
|
+
0,
|
191
|
+
null,
|
192
|
+
null,
|
193
|
+
null,
|
194
|
+
null,
|
195
|
+
null,
|
196
|
+
null,
|
197
|
+
null,
|
198
|
+
null,
|
199
|
+
null,
|
200
|
+
0,
|
201
|
+
null,
|
202
|
+
null,
|
203
|
+
null,
|
204
|
+
null,
|
205
|
+
null,
|
206
|
+
0,
|
207
|
+
null,
|
208
|
+
null,
|
209
|
+
null,
|
210
|
+
null,
|
211
|
+
null,
|
212
|
+
null,
|
213
|
+
0,
|
214
|
+
null,
|
215
|
+
null,
|
216
|
+
null,
|
217
|
+
1,
|
218
|
+
0,
|
219
|
+
null,
|
220
|
+
null,
|
221
|
+
null,
|
222
|
+
null,
|
223
|
+
null,
|
224
|
+
null,
|
225
|
+
null,
|
226
|
+
null,
|
227
|
+
null,
|
228
|
+
null,
|
229
|
+
null,
|
230
|
+
null,
|
231
|
+
null,
|
232
|
+
null,
|
233
|
+
null,
|
234
|
+
null,
|
235
|
+
null,
|
236
|
+
null,
|
237
|
+
null,
|
238
|
+
null,
|
239
|
+
null,
|
240
|
+
null,
|
241
|
+
null,
|
242
|
+
null,
|
243
|
+
null,
|
244
|
+
null,
|
245
|
+
null,
|
246
|
+
null,
|
247
|
+
null,
|
248
|
+
null,
|
249
|
+
null,
|
250
|
+
null,
|
251
|
+
null,
|
252
|
+
null,
|
253
|
+
null,
|
254
|
+
null,
|
255
|
+
null,
|
256
|
+
null,
|
257
|
+
null,
|
258
|
+
null,
|
259
|
+
null,
|
260
|
+
null,
|
261
|
+
null,
|
262
|
+
null,
|
263
|
+
null,
|
264
|
+
null,
|
265
|
+
null,
|
266
|
+
null
|
267
|
+
],
|
268
|
+
"/Users/jenningsanderson/Documents/epic-geo/lib/geojson/write_geojson_featurecollection.rb": [
|
269
|
+
null,
|
270
|
+
null,
|
271
|
+
null,
|
272
|
+
1,
|
273
|
+
null,
|
274
|
+
1,
|
275
|
+
null,
|
276
|
+
1,
|
277
|
+
null,
|
278
|
+
1,
|
279
|
+
0,
|
280
|
+
0,
|
281
|
+
0,
|
282
|
+
null,
|
283
|
+
0,
|
284
|
+
null,
|
285
|
+
null,
|
286
|
+
1,
|
287
|
+
0,
|
288
|
+
null,
|
289
|
+
null,
|
290
|
+
1,
|
291
|
+
0,
|
292
|
+
0,
|
293
|
+
0,
|
294
|
+
null,
|
295
|
+
0,
|
296
|
+
null,
|
297
|
+
null,
|
298
|
+
1,
|
299
|
+
0,
|
300
|
+
0,
|
301
|
+
0,
|
302
|
+
0,
|
303
|
+
0,
|
304
|
+
null,
|
305
|
+
null,
|
306
|
+
1,
|
307
|
+
0,
|
308
|
+
0,
|
309
|
+
null,
|
310
|
+
null,
|
311
|
+
1,
|
312
|
+
null,
|
313
|
+
0,
|
314
|
+
0,
|
315
|
+
null,
|
316
|
+
null,
|
317
|
+
0,
|
318
|
+
0,
|
319
|
+
null,
|
320
|
+
null,
|
321
|
+
null
|
322
|
+
]
|
323
|
+
},
|
324
|
+
"timestamp": 1399675874
|
325
|
+
}
|
326
|
+
}
|
data/epic-geo.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "epic-geo"
|
3
|
+
s.version = "0.0.3"
|
4
|
+
s.platform = Gem::Platform::RUBY
|
5
|
+
s.authors = ["Jennings Anderson"]
|
6
|
+
s.email = ["jennings.anderson@colorado.edu"]
|
7
|
+
s.homepage = "http://github.com/jenningsanderson/epic-geo"
|
8
|
+
s.summary = "Gems for handling Project EPIC geo data"
|
9
|
+
s.description = "Series of Ruby Scripts for dealing with Geo data. Much more to come"
|
10
|
+
s.rubyforge_project = s.name
|
11
|
+
|
12
|
+
#s.required_rubygems_version = ">= 1.3.6"
|
13
|
+
|
14
|
+
# If you have runtime dependencies, add them here
|
15
|
+
# s.add_runtime_dependency "other", "~> 1.2"
|
16
|
+
s.add_runtime_dependency "json"
|
17
|
+
s.add_runtime_dependency "rgeo" #This is an important dependency to allow the geo calculations
|
18
|
+
# It will need all sorts of dependencies such as rgeo, ruby/gems, etc...
|
19
|
+
|
20
|
+
# If you have development dependencies, add them here
|
21
|
+
# s.add_development_dependency "another", "= 0.9"
|
22
|
+
|
23
|
+
# The list of files to be contained in the gem
|
24
|
+
s.files = `git ls-files`.split("\n")
|
25
|
+
# s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
26
|
+
# s.extensions = `git ls-files ext/extconf.rb`.split("\n")
|
27
|
+
|
28
|
+
s.require_path = 'lib'
|
29
|
+
|
30
|
+
# For C extensions
|
31
|
+
# s.extensions = "ext/extconf.rb"
|
32
|
+
end
|
data/lib/epic-geo.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
'''
|
2
|
+
Write a geojson feature collection
|
3
|
+
'''
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
class GeoJSONWriter
|
7
|
+
|
8
|
+
attr_reader :filename
|
9
|
+
|
10
|
+
def initialize(filename)
|
11
|
+
@filename = filename.dup #Getting weird frozen error...
|
12
|
+
unless @filename =~ /\.geojson$/
|
13
|
+
@filename << '.geojson'
|
14
|
+
end
|
15
|
+
@open_file = File.open(@filename, 'w')
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_options(options_hash)
|
19
|
+
@options = options_hash
|
20
|
+
end
|
21
|
+
|
22
|
+
def write_header
|
23
|
+
@open_file.write "{\"type\" : \"FeatureCollection\","
|
24
|
+
unless @options.nil?
|
25
|
+
@open_file.write @options.to_json
|
26
|
+
end
|
27
|
+
@open_file.write "\"features\" :["
|
28
|
+
end
|
29
|
+
|
30
|
+
def write_feature(geometry, properties)
|
31
|
+
@open_file.write "{"
|
32
|
+
@open_file.write "\"type\" : \"Feature\", "
|
33
|
+
@open_file.write "\"geometry\" : #{geometry.to_json},"
|
34
|
+
@open_file.write "\"properties\" : #{properties.to_json}"
|
35
|
+
@open_file.write "},"
|
36
|
+
end
|
37
|
+
|
38
|
+
def literal_write_feature(feature)
|
39
|
+
@open_file.write(feature)
|
40
|
+
@open_file.write(",")
|
41
|
+
end
|
42
|
+
|
43
|
+
def write_footer
|
44
|
+
#Close the file and then truncate the last comma
|
45
|
+
@open_file.close()
|
46
|
+
File.truncate(@filename, File.size(@filename) - 1) #Remove the last comma
|
47
|
+
|
48
|
+
#Open the file again and close the object
|
49
|
+
File.open(@filename,'a') do |file|
|
50
|
+
file.write(']}')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end #end class
|
@@ -0,0 +1,150 @@
|
|
1
|
+
def add_style(current_file, style)
|
2
|
+
current_file.write "<Style id=\"#{style[:id]}\">"
|
3
|
+
if style.has_key? :polygon
|
4
|
+
current_file.write "<PolyStyle>"
|
5
|
+
current_file.write "\t<color>#{style[:polygon][:color]}</color>"
|
6
|
+
current_file.write "</PolyStyle>"
|
7
|
+
end
|
8
|
+
current_file.write "</Style>"
|
9
|
+
end
|
10
|
+
|
11
|
+
def random_hex_color
|
12
|
+
(0..5).map{ rand(16).to_s(16) }.join
|
13
|
+
end
|
14
|
+
|
15
|
+
def write_color_ramp_style(number_of_styles)
|
16
|
+
|
17
|
+
#Base color:
|
18
|
+
base_color = '7714E7FF'
|
19
|
+
step = 256/number_of_styles
|
20
|
+
|
21
|
+
vals = (0..number_of_styles).to_a.reverse
|
22
|
+
vals.each do |id|
|
23
|
+
val = (id*step).to_s(16)
|
24
|
+
val.upcase!
|
25
|
+
if val.length==1
|
26
|
+
val = '0'+val
|
27
|
+
end
|
28
|
+
color = base_color[0..3]+val+base_color[6..7]
|
29
|
+
|
30
|
+
#Open the Style
|
31
|
+
@openfile.write "<Style id=\"c_ramp_style_#{id-1}\">\n"
|
32
|
+
@openfile.write %Q{\t<LabelStyle>
|
33
|
+
<scale>0</scale>
|
34
|
+
</LabelStyle>
|
35
|
+
}
|
36
|
+
|
37
|
+
#Point
|
38
|
+
@openfile.write %Q{\t<IconStyle>
|
39
|
+
<color>#{color}</color>
|
40
|
+
<scale>.3</scale>
|
41
|
+
<Icon>http://maps.google.com/mapfiles/kml/paddle/wht-blank-lv.png</Icon>
|
42
|
+
<LabelStyle>
|
43
|
+
<scale>.1</scale>
|
44
|
+
</LabelStyle>
|
45
|
+
</IconStyle>\n}
|
46
|
+
|
47
|
+
#Line
|
48
|
+
@openfile.write %Q{\t<LineStyle>
|
49
|
+
<color>#{color}</color>
|
50
|
+
<width>1.5</width>
|
51
|
+
</LineStyle>\n}
|
52
|
+
|
53
|
+
#Poly
|
54
|
+
@openfile.write %Q{\t<PolyStyle>
|
55
|
+
<color>#{color}</color>
|
56
|
+
<BalloonStyle>
|
57
|
+
<text><h1>$[name]</h1>$[description]</text>
|
58
|
+
<bgColor>ffd5efff</bgColor>
|
59
|
+
</BalloonStyle>
|
60
|
+
</PolyStyle>\n}
|
61
|
+
@openfile.write "</Style>\n\n"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def generate_random_styles(current_file, number_of_styles)
|
66
|
+
number_of_styles.times do |id|
|
67
|
+
#Generate a random hex color
|
68
|
+
color = random_hex_color
|
69
|
+
|
70
|
+
#Open the Style
|
71
|
+
current_file.write "<Style id=\"r_style_#{id}\">\n"
|
72
|
+
|
73
|
+
#Point
|
74
|
+
current_file.write %Q{\t<IconStyle>
|
75
|
+
<color>77#{color}</color>
|
76
|
+
<scale>.5</scale>
|
77
|
+
<Icon>http://maps.google.com/mapfiles/kml/paddle/wht-blank-lv.png</Icon>
|
78
|
+
<LabelStyle>
|
79
|
+
<scale>0</scale>
|
80
|
+
</LabelStyle>
|
81
|
+
</IconStyle>\n}
|
82
|
+
|
83
|
+
#Line
|
84
|
+
current_file.write %Q{\t<LineStyle>
|
85
|
+
<color>77#{color}</color>
|
86
|
+
<width>1.5</width>
|
87
|
+
</LineStyle>\n}
|
88
|
+
|
89
|
+
#Poly
|
90
|
+
current_file.write %Q{\t<PolyStyle>
|
91
|
+
<color>AA#{color}</color>
|
92
|
+
<BalloonStyle>
|
93
|
+
<text><h1>$[name]</h1>$[description]</text>
|
94
|
+
<bgColor>ffd5efff</bgColor>
|
95
|
+
</BalloonStyle>
|
96
|
+
</PolyStyle>\n}
|
97
|
+
current_file.write "</Style>\n\n"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def write_3_bin_styles
|
102
|
+
current_file.write %Q{
|
103
|
+
<Style id="before">
|
104
|
+
<IconStyle>
|
105
|
+
<scale>0.4</scale>
|
106
|
+
<Icon>
|
107
|
+
<href>http://maps.google.com/mapfiles/kml/paddle/grn-blank-lv.png</href>
|
108
|
+
</Icon>
|
109
|
+
</IconStyle>
|
110
|
+
<LabelStyle>
|
111
|
+
<scale>0</scale>
|
112
|
+
</LabelStyle>
|
113
|
+
<LineStyle>
|
114
|
+
<color>ff5bbd00</color>
|
115
|
+
<width>1.4</width>
|
116
|
+
</LineStyle>
|
117
|
+
</Style>
|
118
|
+
|
119
|
+
<Style id="during">
|
120
|
+
<IconStyle>
|
121
|
+
<scale>0.4</scale>
|
122
|
+
<Icon>
|
123
|
+
<href>http://maps.google.com/mapfiles/kml/paddle/red-circle-lv.png</href>
|
124
|
+
</Icon>
|
125
|
+
</IconStyle>
|
126
|
+
<LabelStyle>
|
127
|
+
<scale>0</scale>
|
128
|
+
</LabelStyle>
|
129
|
+
<LineStyle>
|
130
|
+
<color>ff1515a6</color>
|
131
|
+
<width>1.4</width>
|
132
|
+
</LineStyle>
|
133
|
+
</Style>
|
134
|
+
|
135
|
+
<Style id="after">
|
136
|
+
<IconStyle>
|
137
|
+
<scale>0.4</scale>
|
138
|
+
<Icon>
|
139
|
+
<href>http://maps.google.com/mapfiles/kml/paddle/ylw-blank-lv.png</href>
|
140
|
+
</Icon>
|
141
|
+
</IconStyle>
|
142
|
+
<LabelStyle>
|
143
|
+
<scale>0</scale>
|
144
|
+
</LabelStyle>
|
145
|
+
<LineStyle>
|
146
|
+
<color>ff7fffff</color>
|
147
|
+
<width>1.4</width>
|
148
|
+
</LineStyle>
|
149
|
+
</Style>}
|
150
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'time'
|
2
|
+
require 'georuby'
|
3
|
+
require 'geo_ruby/kml' #Allows writing of georuby geometry objects to kml format
|
4
|
+
|
5
|
+
#TODO: The geometry should come in as geojson, I want to do away with all external dependencies
|
6
|
+
# except for explicit calculations with rgeo.
|
7
|
+
|
8
|
+
#Require the helper functions for writing the styles to the KML file
|
9
|
+
require_relative 'kml_style_helper'
|
10
|
+
|
11
|
+
class KMLAuthor
|
12
|
+
|
13
|
+
attr_reader :filename, :openfile
|
14
|
+
|
15
|
+
def initialize(filename)
|
16
|
+
@filename = filename.dup #Getting weird frozen error...
|
17
|
+
unless @filename =~ /\.kml$/
|
18
|
+
@filename << '.kml'
|
19
|
+
end
|
20
|
+
@openfile = File.open(@filename, 'w')
|
21
|
+
end
|
22
|
+
|
23
|
+
#Write the KML header information and give the the file a name
|
24
|
+
def write_header(title)
|
25
|
+
@openfile.write "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
26
|
+
@openfile.write "<kml xmlns=\"http://earth.google.com/kml/2.1\">\n"
|
27
|
+
@openfile.write "<Document>\n<name>#{title}</name>\n\n"
|
28
|
+
end
|
29
|
+
|
30
|
+
#The main workhorse -- a beautiful recursive function (if I may say so) to write folders to the document
|
31
|
+
def write_folder(folder)
|
32
|
+
@openfile.write "<Folder>\n<name>#{folder[:name]}</name>\n"
|
33
|
+
|
34
|
+
unless folder[:folders].nil?
|
35
|
+
folder[:folders].each do |inner_folder|
|
36
|
+
write_folder(inner_folder)
|
37
|
+
end
|
38
|
+
else
|
39
|
+
unless folder[:features].empty?
|
40
|
+
folder[:features].each do |feature|
|
41
|
+
write_placemark(feature)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
@openfile.write "</Folder>\n\n"
|
46
|
+
end
|
47
|
+
|
48
|
+
#Each placemark can be thought of as a feature in a geojson collection, there are many options, certainly not
|
49
|
+
def write_placemark(feature)
|
50
|
+
@openfile.write "<Placemark>\n"
|
51
|
+
unless feature[:name].nil?
|
52
|
+
@openfile.write "\t<name>#{feature[:name]}</name>\n"
|
53
|
+
end
|
54
|
+
if feature.has_key? :style
|
55
|
+
@openfile.write "\t<styleUrl>#{feature[:style]}</styleUrl>\n"
|
56
|
+
end
|
57
|
+
if feature.has_key? :extended
|
58
|
+
@openfile.write "\t<ExtendedData>\n"
|
59
|
+
feature[:extended].each do |k,v|
|
60
|
+
@openfile.write "\t\t<Data name=\"#{k}\">#{v}</Data>\n"
|
61
|
+
end
|
62
|
+
@openfile.write "\t</ExtendedData>\n"
|
63
|
+
end
|
64
|
+
if feature.has_key? :desc
|
65
|
+
if feature.has_key? :link
|
66
|
+
@openfile.write "\t<description>\n\t\t#{feature[:desc]}\n<![CDATA[<img src=\"#{feature[:link]}\">]]></description>\n"
|
67
|
+
else
|
68
|
+
@openfile.write "\t<description>\n\t\t#{feature[:desc]}\n\t</description>\n"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
if feature.has_key? :time
|
72
|
+
@openfile.write "\t<TimeStamp>\n"
|
73
|
+
@openfile.write "\t\t<when>#{feature[:time].iso8601}</when>\n"
|
74
|
+
@openfile.write "\t</TimeStamp>"
|
75
|
+
end
|
76
|
+
if feature.has_key? :gxTrack
|
77
|
+
@openfile.write %Q{\t<gx:Track>
|
78
|
+
\t\t<altitudeMode>absolute</altitudeMode>
|
79
|
+
\t\t<when>#{feature[:gxTrack][:start][:time].iso8601}</when>
|
80
|
+
\t\t<when>#{feature[:gxTrack][:end][:time].iso8601}</when>
|
81
|
+
\t\t<gx:coord>#{feature[:gxTrack][:start][:pos]}</gx:coord>
|
82
|
+
\t\t<gx:coord>#{feature[:gxTrack][:end][:pos]}</gx:coord>
|
83
|
+
\t</gx:Track>}
|
84
|
+
end
|
85
|
+
|
86
|
+
unless feature[:geometry].nil?
|
87
|
+
@openfile.write "\t"+feature[:geometry].as_kml #What type of geometry do we need here?
|
88
|
+
end
|
89
|
+
@openfile.write "</Placemark>\n\n"
|
90
|
+
end
|
91
|
+
|
92
|
+
#Properly close the kml file
|
93
|
+
def write_footer
|
94
|
+
@openfile.write("\n</Document>\n</kml>")
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
puts "hello world"
|
data/spec/kml_spec.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe KMLAuthor do
|
4
|
+
before :all do
|
5
|
+
@testfile = KMLAuthor.new('testfile')
|
6
|
+
end
|
7
|
+
|
8
|
+
after :all do
|
9
|
+
File.delete('testfile.kml')
|
10
|
+
end
|
11
|
+
|
12
|
+
it "Successfully names it appropriately" do
|
13
|
+
@testfile.filename.should == 'testfile.kml'
|
14
|
+
end
|
15
|
+
|
16
|
+
it "Successfully Opens file" do
|
17
|
+
expect(File).to exist('testfile.kml')
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
require 'coveralls'
|
9
|
+
Coveralls.wear!
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
13
|
+
config.run_all_when_everything_filtered = true
|
14
|
+
config.filter_run :focus
|
15
|
+
|
16
|
+
# Run specs in random order to surface order dependencies. If you find an
|
17
|
+
# order dependency and want to debug it, you can fix the order by providing
|
18
|
+
# the seed, which is printed after each run.
|
19
|
+
# --seed 1234
|
20
|
+
config.order = 'random'
|
21
|
+
end
|
22
|
+
|
23
|
+
#Require the gem
|
24
|
+
require "epic-geo"
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: epic-geo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jennings Anderson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rgeo
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Series of Ruby Scripts for dealing with Geo data. Much more to come
|
42
|
+
email:
|
43
|
+
- jennings.anderson@colorado.edu
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .travis.yml
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- coverage/.last_run.json
|
54
|
+
- coverage/.resultset.json
|
55
|
+
- epic-geo.gemspec
|
56
|
+
- lib/epic-geo.rb
|
57
|
+
- lib/geojson/write_geojson_featurecollection.rb
|
58
|
+
- lib/kml/kml_style_helper.rb
|
59
|
+
- lib/kml/kml_writer.rb
|
60
|
+
- spec/geojson_spec.rb
|
61
|
+
- spec/kml_spec.rb
|
62
|
+
- spec/spec_helper.rb
|
63
|
+
homepage: http://github.com/jenningsanderson/epic-geo
|
64
|
+
licenses: []
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project: epic-geo
|
82
|
+
rubygems_version: 2.0.3
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Gems for handling Project EPIC geo data
|
86
|
+
test_files: []
|