require 'geo_ruby/simple_features/geometry' module GeoRuby module SimpleFeatures #Represents a collection of arbitrary geometries class GeometryCollection < Geometry attr_reader :geometries def initialize(srid = DEFAULT_SRID,with_z=false,with_m=false) super(srid,with_z,with_m) @geometries = [] end #Delegate the unknown methods to the geometries array def method_missing(method_name,*args,&b) @geometries.send(method_name,*args,&b) end #Bounding box in 2D/3D. Returns an array of 2 points def bounding_box max_x, min_x, max_y, min_y = -Float::MAX, Float::MAX, -Float::MAX, Float::MAX, -Float::MAX, Float::MAX if with_z max_z, min_z = -Float::MAX, Float::MAX each do |geometry| bbox = geometry.bounding_box sw = bbox[0] ne = bbox[1] max_y = ne.y if ne.y > max_y min_y = sw.y if sw.y < min_y max_x = ne.x if ne.x > max_x min_x = sw.x if sw.x < min_x max_z = ne.z if ne.z > max_z min_z = sw.z if sw.z < min_z end [Point.from_x_y_z(min_x,min_y,min_z),Point.from_x_y_z(max_x,max_y,max_z)] else each do |geometry| bbox = geometry.bounding_box sw = bbox[0] ne = bbox[1] max_y = ne.y if ne.y > max_y min_y = sw.y if sw.y < min_y max_x = ne.x if ne.x > max_x min_x = sw.x if sw.x < min_x end [Point.from_x_y(min_x,min_y),Point.from_x_y(max_x,max_y)] end end #tests the equality of geometry collections def ==(other_collection) if(other_collection.class != self.class) false elsif length != other_collection.length false else index=0 while index