Class: Geos::Point

Inherits:
Object
  • Object
show all
Defined in:
lib/geos/point.rb,
lib/geos/yaml/syck.rb

Instance Method Summary collapse

Instance Method Details

#as_geojson(options = {}) ⇒ Object Also known as: to_geojsonable



111
112
113
114
115
116
# File 'lib/geos/point.rb', line 111

def as_geojson(options = {})
  {
    :type => 'Point',
    :coordinates => self.to_a
  }
end

#as_json(options = {}) ⇒ Object Also known as: to_jsonable

Returns a Hash suitable for converting to JSON.



101
102
103
104
105
106
107
108
# File 'lib/geos/point.rb', line 101

def as_json(options = {})
  cs = self.coord_seq
  if self.has_z?
    { :type => 'point', :lat => cs.get_y(0), :lng => cs.get_x(0), :z => cs.get_z(0) }
  else
    { :type => 'point', :lat => cs.get_y(0), :lng => cs.get_x(0) }
  end
end

#to_aObject

Returns the Point’s coordinates as an Array in the following format:

[ x, y, z ]

The Z coordinate will only be present for Points which have a Z dimension.



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/geos/point.rb', line 51

def to_a
  if defined?(@to_a)
    @to_a
  else
    cs = self.coord_seq
    @to_a = if self.has_z?
      [ cs.get_x(0), cs.get_y(0), cs.get_z(0) ]
    else
      [ cs.get_x(0), cs.get_y(0) ]
    end
  end
end

#to_georss(*args) ⇒ Object

Build some XmlMarkup for GeoRSS. You should include the appropriate georss and gml XML namespaces in your document.



91
92
93
94
95
96
97
98
# File 'lib/geos/point.rb', line 91

def to_georss(*args)
  xml = Geos::Helper.xml_options(*args)[0]
  xml.georss(:where) do
    xml.gml(:Point) do
      xml.gml(:pos, "#{self.lat} #{self.lng}")
    end
  end
end

#to_kml(*args) ⇒ Object

Build some XmlMarkup for KML. You can set KML options for extrude and altitudeMode. Use Rails/Ruby-style code and it will be converted appropriately, i.e. :altitude_mode, not :altitudeMode.



80
81
82
83
84
85
86
87
# File 'lib/geos/point.rb', line 80

def to_kml(*args)
  xml, options = Geos::Helper.xml_options(*args)
  xml.Point(:id => options[:id]) do
    xml.extrude(options[:extrude]) if options[:extrude]
    xml.altitudeMode(Geos::Helper.camelize(options[:altitude_mode])) if options[:altitude_mode]
    xml.coordinates(self.to_a.join(','))
  end
end

#xObject

Returns the X coordinate of the Point.



21
22
23
# File 'lib/geos/point.rb', line 21

def x
  self.to_a[0]
end

#yObject

Returns the Y coordinate of the Point.



6
7
8
# File 'lib/geos/point.rb', line 6

def y
  self.to_a[1]
end

#zObject

Returns the Z coordinate of the Point.



36
37
38
39
40
41
42
# File 'lib/geos/point.rb', line 36

def z
  if self.has_z?
    self.to_a[2]
  else
    nil
  end
end