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.



18
19
20
# File 'lib/geos/geometry_collection.rb', line 18

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

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



53
54
55
56
57
58
# File 'lib/geos/geometry_collection.rb', line 53

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.



30
31
32
33
34
# File 'lib/geos/geometry_collection.rb', line 30

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

#dump_points(cur_path = []) ⇒ Object

Dumps points similarly to the PostGIS ST_DumpPoints function.



62
63
64
65
66
67
# File 'lib/geos/geometry_collection.rb', line 62

def dump_points(cur_path = [])
  self.each do |geom|
    cur_path << geom.dump_points
  end
  cur_path
end

#eachObject

Iterates the collection through the given block.



10
11
12
13
14
15
# File 'lib/geos/geometry_collection.rb', line 10

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.



25
26
27
# File 'lib/geos/geometry_collection.rb', line 25

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.



49
50
51
# File 'lib/geos/geometry_collection.rb', line 49

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

#to_kml(*args) ⇒ Object

Build some XmlMarkup for KML.



38
39
40
41
42
# File 'lib/geos/geometry_collection.rb', line 38

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