schleyfox-ruby_kml 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,220 @@
1
+ require "#{File.dirname(__FILE__)}/test_helper"
2
+
3
+ class KMLFileTest < Test::Unit::TestCase
4
+ include KML
5
+
6
+ def test_placemark
7
+ kml = KMLFile.new
8
+ kml.objects << Placemark.new(
9
+ :name => 'Simple placemark',
10
+ :description => 'Attached to the ground. Intelligently places itself at the height of the underlying terrain.',
11
+ :geometry => Point.new(:coordinates=>'-122.0822035425683,37.42228990140251,0')
12
+ )
13
+ write_and_show(kml, File.dirname(__FILE__) + '/simple_placemark.kml')
14
+ end
15
+
16
+ def test_cdata_description
17
+ description = <<-DESC
18
+ <h1>CDATA Tags are useful!</h1>
19
+ <p><font color="red">Text is <i>more readable</i> and
20
+ <b>easier to write</b> when you can avoid using entity
21
+ references.</font></p>
22
+ DESC
23
+
24
+ kml = KMLFile.new
25
+ document = Document.new(
26
+ :name => 'Document with CDATA example',
27
+ :snippet => Snippet.new("Document level snippet")
28
+ )
29
+ document.features << Placemark.new(
30
+ :name => 'CDATA example',
31
+ :description => description,
32
+ :snippet => Snippet.new("Example of a snippet"),
33
+ :geometry => Point.new(:coordinates=>'-122.0822035425683,37.4228,0')
34
+ )
35
+ kml.objects << document
36
+ write_and_show(kml, File.dirname(__FILE__) + '/cdata_and_snippet.kml')
37
+ end
38
+
39
+ def test_ground_overlays
40
+ kml = KMLFile.new
41
+ folder = Folder.new(
42
+ :name => 'Ground Overlays',
43
+ :description => 'Examples of ground overlays'
44
+ )
45
+ folder.features << GroundOverlay.new(
46
+ :name => 'Large-scale overlay on terrain',
47
+ :description => 'Overlay shows Mount Etna erupting on July 13th, 2001.',
48
+ :icon => Icon.new(:href => 'http://code.google.com/apis/kml/documentation/etna.jpg'),
49
+ :lat_lon_box => LatLonBox.new(
50
+ :north => 37.91904192681665,
51
+ :south => 37.46543388598137,
52
+ :east => 15.35832653742206,
53
+ :west => 14.60128369746704,
54
+ :rotation => -0.1556640799496235
55
+ )
56
+ )
57
+ kml.objects << folder
58
+ write_and_show(kml, File.dirname(__FILE__) + '/ground_overlays.kml')
59
+ end
60
+
61
+ def test_paths
62
+ kml = KMLFile.new
63
+ kml.objects << Document.new(
64
+ :name => 'Paths',
65
+ :description => 'Examples of paths. Note that the tessellate tag is by default
66
+ set to 0. If you want to create tessellated lines, they must be authored
67
+ (or edited) directly in KML.',
68
+ :styles => [
69
+ Style.new(
70
+ :id => 'yellowLineGreenPoly',
71
+ :line_style => LineStyle.new(:color => '7f00ffff', :width => 4),
72
+ :poly_style => PolyStyle.new(:color => '7f00ff00')
73
+ )
74
+ ],
75
+ :features => [
76
+ Placemark.new(
77
+ :name => 'Absolute Extruded',
78
+ :description => 'Transparent green wall with yellow outlines',
79
+ :style_url => '#yellowLineGreenPoly',
80
+ :geometry => LineString.new(
81
+ :extrude => true,
82
+ :tessellate => true,
83
+ :altitude_mode => 'absolute',
84
+ :coordinates => '-112.2550785337791,36.07954952145647,2357
85
+ -112.2549277039738,36.08117083492122,2357
86
+ -112.2552505069063,36.08260761307279,2357
87
+ -112.2564540158376,36.08395660588506,2357
88
+ -112.2580238976449,36.08511401044813,2357
89
+ -112.2595218489022,36.08584355239394,2357
90
+ -112.2608216347552,36.08612634548589,2357
91
+ -112.262073428656,36.08626019085147,2357
92
+ -112.2633204928495,36.08621519860091,2357
93
+ -112.2644963846444,36.08627897945274,2357
94
+ -112.2656969554589,36.08649599090644,2357'
95
+ )
96
+ )
97
+ ]
98
+ )
99
+ #puts kml.render
100
+ write_and_show(kml, File.dirname(__FILE__) + '/paths.kml')
101
+ end
102
+
103
+ def test_polygon
104
+ kml = KMLFile.new
105
+ kml.objects << Placemark.new(
106
+ :name => 'The Pentagon',
107
+ :geometry => Polygon.new(
108
+ :extrude => true,
109
+ :altitude_mode => 'relativeToGround',
110
+ :outer_boundary_is => LinearRing.new(
111
+ :coordinates => '-77.05788457660967,38.87253259892824,100
112
+ -77.05465973756702,38.87291016281703,100
113
+ -77.05315536854791,38.87053267794386,100
114
+ -77.05552622493516,38.868757801256,100
115
+ -77.05844056290393,38.86996206506943,100
116
+ -77.05788457660967,38.87253259892824,100'
117
+ ),
118
+ :inner_boundary_is => LinearRing.new(
119
+ :coordinates => '-77.05668055019126,38.87154239798456,100
120
+ -77.05542625960818,38.87167890344077,100
121
+ -77.05485125901024,38.87076535397792,100
122
+ -77.05577677433152,38.87008686581446,100
123
+ -77.05691162017543,38.87054446963351,100
124
+ -77.05668055019126,38.87154239798456,100'
125
+ )
126
+ )
127
+ )
128
+
129
+ #puts kml.render
130
+ write_and_show(kml, File.dirname(__FILE__) + '/polygon.kml')
131
+ end
132
+
133
+ def test_geometry_styles
134
+ kml = KMLFile.new
135
+ kml.objects << Style.new(
136
+ :id => "transBluePoly",
137
+ :line_style => LineStyle.new(
138
+ :width => 1.5
139
+ ),
140
+ :poly_style => PolyStyle.new(
141
+ :color => '7dff0000'
142
+ )
143
+ )
144
+ kml.objects << Placemark.new(
145
+ :name => 'Building 41',
146
+ :style_url => '#transBluePoly',
147
+ :geometry => Polygon.new(
148
+ :extrude => true,
149
+ :altitude_mode => 'relativeToGround',
150
+ :outer_boundary_is => LinearRing.new(
151
+ :coordinates => '-122.0857412771483,37.42227033155257,17
152
+ -122.0858169768481,37.42231408832346,17
153
+ -122.085852582875,37.42230337469744,17
154
+ -122.0858799945639,37.42225686138789,17
155
+ -122.0858860101409,37.4222311076138,17
156
+ -122.0858069157288,37.42220250173855,17
157
+ -122.0858379542653,37.42214027058678,17
158
+ -122.0856732640519,37.42208690214408,17
159
+ -122.0856022926407,37.42214885429042,17
160
+ -122.0855902778436,37.422128290487,17
161
+ -122.0855841672237,37.42208171967246,17
162
+ -122.0854852065741,37.42210455874995,17
163
+ -122.0855067264352,37.42214267949824,17
164
+ -122.0854430712915,37.42212783846172,17
165
+ -122.0850990714904,37.42251282407603,17
166
+ -122.0856769818632,37.42281815323651,17
167
+ -122.0860162273783,37.42244918858722,17
168
+ -122.0857260327004,37.42229239604253,17
169
+ -122.0857412771483,37.42227033155257,17'
170
+ )
171
+ )
172
+ )
173
+
174
+ write_and_show(kml, File.dirname(__FILE__) + '/polygon_style.kml')
175
+ end
176
+
177
+ def test_style_map
178
+ kml = KMLFile.new
179
+ kml.objects << Document.new(
180
+ :name => 'Highlighted Icon',
181
+ :description => 'Place your mouse over the icon to see it display the new icon',
182
+ :styles => [
183
+ Style.new(
184
+ :id => "highlightPlacemark",
185
+ :icon_style => IconStyle.new(
186
+ :icon => Icon.new(
187
+ :href => "http://maps.google.com/mapfiles/kml/paddle/red-stars.png"
188
+ )
189
+ )
190
+ ),
191
+ Style.new(
192
+ :id => "normalPlacemark",
193
+ :icon_style => IconStyle.new(
194
+ :icon => Icon.new(
195
+ :href => "http://maps.google.com/mapfiles/kml/paddle/wht-blank.png"
196
+ )
197
+ )
198
+ ),
199
+ StyleMap.new(
200
+ :id => 'exampleStyleMap',
201
+ :pairs => {
202
+ 'normal' => '#normalPlacemark',
203
+ 'highlight' => '#highlightPlacemark'
204
+ }
205
+ )
206
+ ],
207
+ :features => [
208
+ Placemark.new(
209
+ :name => 'Roll over this icon',
210
+ :style_url => '#exampleStyleMap',
211
+ :geometry => Point.new(
212
+ :coordinates => '-122.0856545755255,37.42243077405461,0'
213
+ )
214
+ )
215
+ ]
216
+ )
217
+ #puts kml.render
218
+ write_and_show(kml, File.dirname(__FILE__) + '/style_map.kml')
219
+ end
220
+ end
@@ -0,0 +1,23 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
2
+ $:.unshift(File.dirname(__FILE__)) unless
3
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
4
+
5
+ require 'pp'
6
+ require 'test/unit'
7
+
8
+ require 'kml'
9
+
10
+ class Test::Unit::TestCase
11
+ def write_and_show(kml, file)
12
+ #puts kml.render
13
+ File.open(file, 'w') { |f| f.write kml.render }
14
+ show_file(file)
15
+ end
16
+
17
+ def show_file(file)
18
+ #tests should probably not launch visual external applications
19
+ #cmd = "open -a /Applications/Google\\ Earth.app/ #{File.expand_path(file)}"
20
+ #puts "executing command: #{cmd}"
21
+ #`#{cmd}`
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: schleyfox-ruby_kml
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - aeden, schleyfox, xaviershay
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-06-07 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Generate KML files with ruby
17
+ email: ""
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - CHANGELOG
26
+ - LICENSE
27
+ - Rakefile
28
+ - README.textile
29
+ - lib/kml/style.rb
30
+ - lib/kml/hot_spot.rb
31
+ - lib/kml/line_style.rb
32
+ - lib/kml/link.rb
33
+ - lib/kml/point.rb
34
+ - lib/kml/polygon.rb
35
+ - lib/kml/placemark.rb
36
+ - lib/kml/model.rb
37
+ - lib/kml/poly_style.rb
38
+ - lib/kml/line_string.rb
39
+ - lib/kml/geometry.rb
40
+ - lib/kml/snippet.rb
41
+ - lib/kml/color_style.rb
42
+ - lib/kml/folder.rb
43
+ - lib/kml/lat_lon_box.rb
44
+ - lib/kml/linear_ring.rb
45
+ - lib/kml/style_map.rb
46
+ - lib/kml/object.rb
47
+ - lib/kml/document.rb
48
+ - lib/kml/icon.rb
49
+ - lib/kml/icon_style.rb
50
+ - lib/kml/container.rb
51
+ - lib/kml/multi_geometry.rb
52
+ - lib/kml/look_at.rb
53
+ - lib/kml/overlay.rb
54
+ - lib/kml/style_selector.rb
55
+ - lib/kml/feature.rb
56
+ - lib/kml/version.rb
57
+ - lib/kml/ground_overlay.rb
58
+ - lib/kml_file.rb
59
+ - lib/kml.rb
60
+ - test/kml/point_test.rb
61
+ - test/kml_file_test.rb
62
+ - test/test_helper.rb
63
+ - examples/melbourne-stations.kml
64
+ has_rdoc: false
65
+ homepage: http://github.com/schleyfox/ruby_kml
66
+ post_install_message:
67
+ rdoc_options: []
68
+
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ requirements: []
84
+
85
+ rubyforge_project:
86
+ rubygems_version: 1.0.1
87
+ signing_key:
88
+ specification_version: 2
89
+ summary: Generate KML files with ruby
90
+ test_files:
91
+ - test/kml/point_test.rb
92
+ - test/kml_file_test.rb
93
+ - test/test_helper.rb