1#!/usr/bin/env ruby
2
3# Copyright 2008, Google Inc. All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are met:
7#
8#  1. Redistributions of source code must retain the above copyright notice,
9#     this list of conditions and the following disclaimer.
10#  2. Redistributions in binary form must reproduce the above copyright notice,
11#     this list of conditions and the following disclaimer in the documentation
12#     and/or other materials provided with the distribution.
13#  3. Neither the name of Google Inc. nor the names of its contributors may be
14#     used to endorse or promote products derived from this software without
15#     specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
18# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
20# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28# This program demonstrates use of the KML DOM Ruby SWIG bindings
29# for creating and accessing array values such as <coordinates>
30# and <Folder>.
31
32require 'setpath'
33
34factory = Kmldom::KmlFactory.GetFactory()
35
36puts "Coordinates is a vector of Vec3..."
37
38coordinates = factory.CreateCoordinates()
39coordinates.add_point2(1,1)
40coordinates.add_point2(2,2)
41coordinates.add_point2(3,3)
42
43for i in 0..coordinates.coordinates_array_size()-1
44  puts "longitude: #{coordinates.coordinates_array_at(i).longitude()}"
45  puts "latitude: #{coordinates.coordinates_array_at(i).latitude()}"
46  puts "altitude: #{coordinates.coordinates_array_at(i).altitude()}"
47end
48
49puts Kmldom::SerializePretty(coordinates)
50
51# Ruby deletes coordinates
52
53puts "Create a Folder with some Features..."
54
55folder = factory.CreateFolder()
56folder.add_feature(factory.CreatePlacemark())
57folder.add_feature(factory.CreateFolder())
58
59for i in 0..folder.feature_array_size()-1
60  puts "feature Type: #{folder.feature_array_at(i).Type()}"
61end
62
63puts Kmldom::SerializePretty(folder)
64
65# Ruby deletes folder which internally deletes its feature list.
66
67