Class: Kamelopard::Point

Inherits:
Geometry show all
Defined in:
lib/kamelopard/classes.rb

Overview

Represents a Point in KML.

Instance Attribute Summary collapse

Attributes inherited from Object

#comment, #kml_id, #master_only

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Object

#_alternate_to_kml, #change, #master_only?

Constructor Details

#initialize(longitude = nil, latitude = nil, altitude = nil, options = {}) ⇒ Point

Returns a new instance of Point.



335
336
337
338
339
340
# File 'lib/kamelopard/classes.rb', line 335

def initialize(longitude = nil, latitude = nil, altitude = nil, options = {})
    super options
    @longitude = Kamelopard.convert_coord(longitude) unless longitude.nil?
    @latitude = Kamelopard.convert_coord(latitude) unless latitude.nil?
    @altitude = altitude unless altitude.nil?
end

Instance Attribute Details

#altitudeObject

Returns the value of attribute altitude.



333
334
335
# File 'lib/kamelopard/classes.rb', line 333

def altitude
  @altitude
end

#altitudeModeObject

Returns the value of attribute altitudeMode.



333
334
335
# File 'lib/kamelopard/classes.rb', line 333

def altitudeMode
  @altitudeMode
end

#extrudeObject

Returns the value of attribute extrude.



333
334
335
# File 'lib/kamelopard/classes.rb', line 333

def extrude
  @extrude
end

#latitudeObject

Returns the value of attribute latitude.



332
333
334
# File 'lib/kamelopard/classes.rb', line 332

def latitude
  @latitude
end

#longitudeObject

Returns the value of attribute longitude.



332
333
334
# File 'lib/kamelopard/classes.rb', line 332

def longitude
  @longitude
end

Class Method Details

.parse(p) ⇒ Object

Converts an XML::Node to a Kamelopard::Point



343
344
345
346
347
# File 'lib/kamelopard/classes.rb', line 343

def self.parse(p)
    a = Kamelopard.xml_to_hash(p, %w[altitudeMode extrude coordinates])
    (lon, lat, alt) = a[:coordinates].to_s.split(/,\s+/).collect { |a| a.to_f }
    return Point.new(lon, lat, alt, :altitudeMode => a[:altitudeMode].to_s.to_sym, :extrude => a[:extrude].to_s.to_i)
end

Instance Method Details

#to_kml(elem = nil, short = false) ⇒ Object



365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# File 'lib/kamelopard/classes.rb', line 365

def to_kml(elem = nil, short = false)
    e = XML::Node.new 'Point'
    super(e)
    e.attributes['id'] = @kml_id
    c = XML::Node.new 'coordinates'
    c << "#{ @longitude }, #{ @latitude }, #{ @altitude }"
    e << c

    if not short then
        c = XML::Node.new 'extrude'
        c << @extrude.to_s
        e << c

        Kamelopard.add_altitudeMode(@altitudeMode, e)
    end

    elem << e unless elem.nil?
    e
end

#to_sObject



357
358
359
# File 'lib/kamelopard/classes.rb', line 357

def to_s
    "Point (#{@longitude}, #{@latitude}, #{@altitude}, mode = #{@altitudeMode}, #{ @extrude == 1 ? 'extruded' : 'not extruded' })"
end