Class GeoRuby::SimpleFeatures::GeometryCollection
In: lib/geo_ruby/simple_features/geometry_collection.rb
Parent: Geometry

Represents a collection of arbitrary geometries

Methods

Attributes

geometries  [R] 

Public Class methods

creates a new GeometryCollection from an array of geometries

[Source]

     # File lib/geo_ruby/simple_features/geometry_collection.rb, line 129
129:       def self.from_geometries(geometries,srid=DEFAULT_SRID,with_z=false,with_m=false)
130:         geometry_collection = new(srid,with_z,with_m)
131:         geometry_collection.concat(geometries)
132:         geometry_collection
133:       end

[Source]

    # File lib/geo_ruby/simple_features/geometry_collection.rb, line 9
 9:       def initialize(srid = DEFAULT_SRID,with_z=false,with_m=false)
10:         super(srid,with_z,with_m)
11:         @geometries = []
12:       end

Public Instance methods

tests the equality of geometry collections

[Source]

    # File lib/geo_ruby/simple_features/geometry_collection.rb, line 67
67:       def ==(other_collection)
68:         if(other_collection.class != self.class)
69:           false
70:         elsif length != other_collection.length
71:           false
72:         else
73:           index=0
74:           while index<length
75:             return false if self[index] != other_collection[index]
76:             index+=1
77:           end
78:           true
79:         end
80:       end

Bounding box in 2D/3D. Returns an array of 2 points

[Source]

    # File lib/geo_ruby/simple_features/geometry_collection.rb, line 20
20:       def bounding_box
21:         max_x, min_x, max_y, min_y = -Float::MAX, Float::MAX, -Float::MAX, Float::MAX, -Float::MAX, Float::MAX 
22:         if with_z
23:           max_z, min_z = -Float::MAX, Float::MAX
24:           each do |geometry|
25:             bbox = geometry.bounding_box
26:             sw = bbox[0]
27:             ne = bbox[1]
28:             
29:             max_y = ne.y if ne.y > max_y
30:             min_y = sw.y if sw.y < min_y
31:             max_x = ne.x if ne.x > max_x
32:             min_x = sw.x if sw.x < min_x 
33:             max_z = ne.z if ne.z > max_z
34:             min_z = sw.z if sw.z < min_z 
35:           end
36:           [Point.from_x_y_z(min_x,min_y,min_z),Point.from_x_y_z(max_x,max_y,max_z)]
37:         else
38:           each do |geometry|
39:             bbox = geometry.bounding_box
40:             sw = bbox[0]
41:             ne = bbox[1]
42:             
43:             max_y = ne.y if ne.y > max_y
44:             min_y = sw.y if sw.y < min_y
45:             max_x = ne.x if ne.x > max_x
46:             min_x = sw.x if sw.x < min_x 
47:           end
48:           [Point.from_x_y(min_x,min_y),Point.from_x_y(max_x,max_y)]
49:         end
50:       end

[Source]

    # File lib/geo_ruby/simple_features/geometry_collection.rb, line 52
52:       def m_range
53:         if with_m
54:           max_m, min_m = -Float::MAX, Float::MAX
55:           each do |lr|
56:             lrmr = lr.m_range
57:             max_m = lrmr[1] if lrmr[1] > max_m
58:             min_m = lrmr[0] if lrmr[0] < min_m
59:           end
60:           [min_m,max_m]
61:         else
62:           [0,0]
63:         end
64:       end

Delegate the unknown methods to the geometries array

[Source]

    # File lib/geo_ruby/simple_features/geometry_collection.rb, line 15
15:       def method_missing(method_name,*args,&b)
16:         @geometries.send(method_name,*args,&b)
17:       end

[Validate]