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.



376
377
378
379
380
381
# File 'lib/kamelopard/classes.rb', line 376

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.



374
375
376
# File 'lib/kamelopard/classes.rb', line 374

def altitude
  @altitude
end

#altitudeModeObject

Returns the value of attribute altitudeMode.



374
375
376
# File 'lib/kamelopard/classes.rb', line 374

def altitudeMode
  @altitudeMode
end

#extrudeObject

Returns the value of attribute extrude.



374
375
376
# File 'lib/kamelopard/classes.rb', line 374

def extrude
  @extrude
end

#latitudeObject

Returns the value of attribute latitude.



373
374
375
# File 'lib/kamelopard/classes.rb', line 373

def latitude
  @latitude
end

#longitudeObject

Returns the value of attribute longitude.



373
374
375
# File 'lib/kamelopard/classes.rb', line 373

def longitude
  @longitude
end

Class Method Details

.parse(p) ⇒ Object

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



384
385
386
387
388
# File 'lib/kamelopard/classes.rb', line 384

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



406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# File 'lib/kamelopard/classes.rb', line 406

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



398
399
400
# File 'lib/kamelopard/classes.rb', line 398

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