lib/geo_ruby/simple_features/envelope.rb in GeoRuby-1.1.0 vs lib/geo_ruby/simple_features/envelope.rb in GeoRuby-1.1.1
- old
+ new
@@ -1,15 +1,15 @@
module GeoRuby
module SimpleFeatures
+ #Contains the bounding box of a geometry
class Envelope
attr_accessor :lower_corner, :upper_corner
attr_accessor :srid, :with_z
#Creates a enw Envelope with +lower_corner+ as the first element of the corners array and +upper_corner+ as the second element
- def initialize(corners, srid = DEFAULT_SRID, with_z = false)
- @lower_corner,@upper_corner = corners
+ def initialize(srid = DEFAULT_SRID, with_z = false)
@srid = srid
@with_z = with_z
end
#Merges the argument with the current evelope
@@ -22,21 +22,30 @@
end
#Merges the argument with the current evelope and sends back a new
#envelope without changing the current one
def extend(envelope)
- e = Envelope.new([Point.from_x_y(lower_corner.x,lower_corner.y),
- Point.from_x_y(upper_corner.x,upper_corner.y)])
+ e = Envelope.from_points([Point.from_x_y(lower_corner.x,lower_corner.y),
+ Point.from_x_y(upper_corner.x,upper_corner.y)],srid,with_z)
e.extend!(envelope)
e
end
#Sends back the center of the envelope
def center
Point.from_x_y((lower_corner.x + upper_corner.x)/2,(lower_corner.y + upper_corner.y)/2)
end
+ #Tests the equality of line strings
+ def ==(other_envelope)
+ if other_envelope.class != self.class
+ false
+ else
+ upper_corner == other_envelope.upper_corner and lower_corner == other_envelope.lower_corner
+ end
+ end
+
#georss serialization: Dialect can be passed as option <tt>:dialect</tt> and set to <tt>:simple</tt> (default)
#<tt>:w3cgeo</tt> or <tt>:gml</tt>. Options <tt>:featuretypetag
def as_georss(options)
dialect= options[:dialect] || :simple
case(dialect)
@@ -103,8 +112,23 @@
result += "<maxAltitude>#{upper_corner.z}</maxAltitude>"
end
result += "</LatLonAltBox>\n"
end
+
+ #Creates a new envelope. Accept an array of 2 points as argument
+ def self.from_points(points,srid=DEFAULT_SRID,with_z=false)
+ e = Envelope.new(srid,with_z)
+ e.lower_corner, e.upper_corner = points
+ e
+ end
+
+ #Creates a new envelope. Accept a sequence of points as argument : ((x,y),(x,y))
+ def self.from_coordinates(points,srid=DEFAULT_SRID,with_z=false)
+ e = Envelope.new(srid,with_z)
+ e.lower_corner, e.upper_corner = points.collect{|point_coords| Point.from_coordinates(point_coords,srid,with_z)}
+ e
+ end
+
end
end
end