Class: Geos::GeometryCollection

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

Direct Known Subclasses

MultiLineString, MultiPoint, MultiPolygon

Instance Method Summary collapse

Instance Method Details

#[](*args) ⇒ Object Also known as: slice

Returns the nth geometry from the collection.



16
17
18
# File 'lib/geos/geometry_collection.rb', line 16

def [](*args)
  self.to_a[*args]
end

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



51
52
53
54
55
56
# File 'lib/geos/geometry_collection.rb', line 51

def as_geojson(options = {})
  {
    :type => 'GeometryCollection',
    :geometries => self.to_a.collect { |g| g.to_geojsonable(options) }
  }
end

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

Returns a Hash suitable for converting to JSON.



28
29
30
31
32
# File 'lib/geos/geometry_collection.rb', line 28

def as_json(options = {})
  self.collect do |p|
    p.to_jsonable options
  end
end

#eachObject

Iterates the collection through the given block.



8
9
10
11
12
13
# File 'lib/geos/geometry_collection.rb', line 8

def each
  self.num_geometries.times do |n|
    yield self.get_geometry_n(n)
  end
  nil
end

#lastObject

Returns the last geometry from the collection.



23
24
25
# File 'lib/geos/geometry_collection.rb', line 23

def last
  self.get_geometry_n(self.num_geometries - 1) if self.num_geometries > 0
end

#to_georss(*args) ⇒ Object

Build some XmlMarkup for GeoRSS. Since GeoRSS is pretty trimed down, we just take the entire collection and use the exterior_ring as a Polygon. Not to bright, mind you, but until GeoRSS stops with the suck, what are we to do. You should include the appropriate georss and gml XML namespaces in your document.



47
48
49
# File 'lib/geos/geometry_collection.rb', line 47

def to_georss(*args)
  self.exterior_ring.to_georss(*args)
end

#to_kml(*args) ⇒ Object

Build some XmlMarkup for KML.



36
37
38
39
40
# File 'lib/geos/geometry_collection.rb', line 36

def to_kml(*args)
  self.collect do |p|
    p.to_kml(*args)
  end
end