Class: GeoRuby::SimpleFeatures::Envelope

Inherits:
Object
  • Object
show all
Defined in:
lib/georuby-ext/georuby/envelope.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.bounds(geometries) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/georuby-ext/georuby/envelope.rb', line 12

def self.bounds(geometries)
  return nil if geometries.blank?

  geometries.inject(geometries.first.envelope) do |envelope, geometry|
    envelope.extend!(geometry.envelope)
  end
end

Instance Method Details

#contains_point?(point) ⇒ Boolean Also known as: contains?

Returns:

  • (Boolean)


3
4
5
6
# File 'lib/georuby-ext/georuby/envelope.rb', line 3

def contains_point?(point)
  (lower_corner.x...upper_corner.x).include?(point.x) and
    (lower_corner.y...upper_corner.y).include?(point.y) 
end

#overlaps?(bound) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/georuby-ext/georuby/envelope.rb', line 8

def overlaps?(bound)
  contains_point?(bound.upper_corner) or contains_point?(bound.lower_corner) or bound.contains_point?(upper_corner) or bound.contains_point?(lower_corner)   
end

#sql_boxObject Also known as: to_sql



22
23
24
# File 'lib/georuby-ext/georuby/envelope.rb', line 22

def sql_box
  "SetSRID('BOX3D(#{upper_corner.lng} #{upper_corner.lat}, #{lower_corner.lng} #{lower_corner.lat})'::box3d, #{srid})"
end

#to_googleObject



32
33
34
# File 'lib/georuby-ext/georuby/envelope.rb', line 32

def to_google
  GeoRuby::SimpleFeatures::Envelope.from_points [lower_corner.to_google, upper_corner.to_google], 900913, with_z
end

#to_openlayersObject



28
29
30
# File 'lib/georuby-ext/georuby/envelope.rb', line 28

def to_openlayers
  OpenLayers::Bounds.new lower_corner.x, lower_corner.y, upper_corner.x, upper_corner.y
end

#to_polygonObject



36
37
38
# File 'lib/georuby-ext/georuby/envelope.rb', line 36

def to_polygon
  GeoRuby::SimpleFeatures::Polygon.from_coordinates( [ [ [lower_corner.x, lower_corner.y], [lower_corner.x, upper_corner.y], [upper_corner.x, upper_corner.y], [upper_corner.x, lower_corner.y] ] ] ) 
end

#to_rgeoObject



40
41
42
# File 'lib/georuby-ext/georuby/envelope.rb', line 40

def to_rgeo
  self.to_polygon.to_rgeo
end