Class: Geos::CoordinateSequence
- Inherits:
-
Object
- Object
- Geos::CoordinateSequence
- Defined in:
- lib/geos/coordinate_sequence.rb
Instance Method Summary collapse
- #as_geojson(options = {}) ⇒ Object (also: #to_geojsonable)
-
#as_json(options = {}) ⇒ Object
(also: #to_jsonable)
Returns a Hash suitable for converting to JSON.
-
#to_a ⇒ Object
Returns a Ruby Array of Arrays of coordinates within the CoordinateSequence in the form [ x, y, z ].
- #to_geojson(options = {}) ⇒ Object
-
#to_georss(*args) ⇒ Object
Build some XmlMarkup for GeoRSS GML.
-
#to_kml(*args) ⇒ Object
Build some XmlMarkup for KML.
Instance Method Details
#as_geojson(options = {}) ⇒ Object Also known as: to_geojsonable
79 80 81 82 83 84 |
# File 'lib/geos/coordinate_sequence.rb', line 79 def as_geojson( = {}) { :type => 'LineString', :coordinates => self.to_a } end |
#as_json(options = {}) ⇒ Object Also known as: to_jsonable
Returns a Hash suitable for converting to JSON.
Options:
-
:encoded - enable or disable Google Maps encoding. The default is true.
-
:level - set the level of the Google Maps encoding algorithm.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/geos/coordinate_sequence.rb', line 58 def as_json( = {}) = { :encoded => true, :level => 3 }.merge if [:encoded] { :type => 'lineString', :encoded => true }.merge(Geos::GoogleMaps::PolylineEncoder.encode(self.to_a, [:level])) else { :type => 'lineString', :encoded => false, :points => self.to_a } end end |
#to_a ⇒ Object
Returns a Ruby Array of Arrays of coordinates within the CoordinateSequence in the form [ x, y, z ].
6 7 8 9 10 11 12 13 14 |
# File 'lib/geos/coordinate_sequence.rb', line 6 def to_a (0...self.length).to_a.collect do |p| [ self.get_x(p), (self.dimensions >= 2 ? self.get_y(p) : nil), (self.dimensions >= 3 && self.get_z(p) > 1.7e-306 ? self.get_z(p) : nil) ].compact end end |
#to_geojson(options = {}) ⇒ Object
87 88 89 |
# File 'lib/geos/coordinate_sequence.rb', line 87 def to_geojson( = {}) self.to_geojsonable().to_json end |
#to_georss(*args) ⇒ Object
Build some XmlMarkup for GeoRSS GML. You should include the appropriate georss and gml XML namespaces in your document.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/geos/coordinate_sequence.rb', line 37 def to_georss(*args) xml = Geos::Helper.(*args)[0] xml.georss(:where) do xml.gml(:LineString) do xml.gml(:posList) do xml << self.to_a.collect do |p| "#{p[1]} #{p[0]}" end.join(' ') end end end end |
#to_kml(*args) ⇒ Object
Build some XmlMarkup for KML. You can set various KML options like tessellate, altitudeMode, etc. Use Rails/Ruby-style code and it will be converted automatically, i.e. :altitudeMode, not :altitude_mode.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/geos/coordinate_sequence.rb', line 20 def to_kml(*args) xml, = Geos::Helper.(*args) xml.LineString(:id => [:id]) do xml.extrude([:extrude]) if [:extrude] xml.tessellate([:tessellate]) if [:tessellate] xml.altitudeMode(Geos::Helper.camelize([:altitude_mode])) if [:altitudeMode] xml.coordinates do self.to_a.each do xml << (self.to_a.join(',')) end end end end |