class GeoRuby::SimpleFeatures::Envelope

Contains the bounding box of a geometry

Attributes

lower_corner[RW]
srid[RW]
upper_corner[RW]
with_z[RW]

Public Class Methods

from_coordinates(points,srid=DEFAULT_SRID,with_z=false) click to toggle source

Creates a new envelope. Accept a sequence of point coordinates as argument : ((x,y),(x,y))

# File lib/geo_ruby/simple_features/envelope.rb, line 126
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
from_points(points,srid=DEFAULT_SRID,with_z=false) click to toggle source

Creates a new envelope. Accept an array of 2 points as argument

# File lib/geo_ruby/simple_features/envelope.rb, line 119
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
new(srid = DEFAULT_SRID, with_z = false) click to toggle source

Creates a enw Envelope with lower_corner as the first element of the corners array and upper_corner as the second element

# File lib/geo_ruby/simple_features/envelope.rb, line 10
def initialize(srid = DEFAULT_SRID, with_z = false)
  @srid = srid
  @with_z = with_z
end

Public Instance Methods

==(other_envelope) click to toggle source

Tests the equality of line strings

# File lib/geo_ruby/simple_features/envelope.rb, line 39
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
as_georss(options = {}) click to toggle source

georss serialization: Dialect can be passed as option :dialect and set to :simple (default) :w3cgeo or :gml. Options <tt>:featuretypetag

# File lib/geo_ruby/simple_features/envelope.rb, line 49
def as_georss(options = {})
  dialect= options[:dialect] || :simple
  case(dialect)
  when :simple
    geom_attr = ""
    geom_attr += " featuretypetag=\"#{options[:featuretypetag]}\"" if options[:featuretypetag]
    geom_attr += " relationshiptag=\"#{options[:relationshiptag]}\"" if options[:relationshiptag]
    geom_attr += " floor=\"#{options[:floor]}\"" if options[:floor]
    geom_attr += " radius=\"#{options[:radius]}\"" if options[:radius]
    geom_attr += " elev=\"#{options[:elev]}\"" if options[:elev]
    
    georss_simple_representation(options.merge(:geom_attr => geom_attr))
  when :w3cgeo
    georss_w3cgeo_representation(options)
  when :gml
    georss_gml_representation(options)
  end
end
as_kml(options = {}) click to toggle source

Sends back a latlonaltbox

# File lib/geo_ruby/simple_features/envelope.rb, line 93
def as_kml(options = {})
  geom_data = ""
  geom_data = "<altitudeMode>#{options[:altitude_mode]}</altitudeMode>\n" if options[:altitude_mode]
  
  allow_z = with_z && (!options[:altitude_mode].nil?) && options[:atitude_mode] != "clampToGround"
  
  kml_representation(options.merge(:geom_data => geom_data,:allow_z => allow_z))
end
center() click to toggle source

Sends back the center of the envelope

# File lib/geo_ruby/simple_features/envelope.rb, line 34
def center
  Point.from_x_y((lower_corner.x + upper_corner.x)/2,(lower_corner.y + upper_corner.y)/2)
end
extend(envelope) click to toggle source

Merges the argument with the current evelope and sends back a new envelope without changing the current one

# File lib/geo_ruby/simple_features/envelope.rb, line 26
def extend(envelope)
  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
extend!(envelope) click to toggle source

Merges the argument with the current evelope

# File lib/geo_ruby/simple_features/envelope.rb, line 16
def extend!(envelope)
  lower_corner.x = [lower_corner.x,envelope.lower_corner.x].min
  lower_corner.y = [lower_corner.y,envelope.lower_corner.y].min
  upper_corner.x = [upper_corner.x,envelope.upper_corner.x].max
  upper_corner.y = [upper_corner.y,envelope.upper_corner.y].max
  self
end