class RGeoServer::BoundingBox

Attributes

maxx[R]
maxy[R]
minx[R]
miny[R]

Public Class Methods

epsilon() click to toggle source
# File lib/rgeoserver/utils/boundingbox.rb, line 9
def self.epsilon
  @@epsilon
end
epsilon=(value) click to toggle source
# File lib/rgeoserver/utils/boundingbox.rb, line 13
def self.epsilon= value
  @@epsilon = value
end
from_a(a) click to toggle source

@param [Array] a in [minx, miny, maxx, maxy]

# File lib/rgeoserver/utils/boundingbox.rb, line 18
def self.from_a a
  self.class.new Hash.new('minx' => a[0].to_f,
                          'miny' => a[1].to_f,
                          'maxx' => a[2].to_f,
                          'maxy' => a[3].to_f)
    
end
new(options = {}) click to toggle source
# File lib/rgeoserver/utils/boundingbox.rb, line 26
def initialize options = {}
  reset
  if ['minx', 'miny', 'maxx', 'maxy'].all? {|k| options.include?(k)}
    add options['minx'].to_f, options['miny'].to_f # SW
    add options['maxx'].to_f, options['maxx'].to_f # NE
  end
end

Public Instance Methods

<<(point) click to toggle source
# File lib/rgeoserver/utils/boundingbox.rb, line 39
def << point
  add point[0], point[1]
end
add(x, y) click to toggle source
# File lib/rgeoserver/utils/boundingbox.rb, line 43
def add x, y
  if @empty
    @minx = @maxx = x
    @miny = @maxy = y
  end

  @minx = [minx, x].min
  @miny = [miny, y].min
  @maxx = [maxx, x].max
  @maxy = [maxy, y].max

  @empty = false
end
area() click to toggle source
# File lib/rgeoserver/utils/boundingbox.rb, line 87
def area
  width * height
end
constrict(rate = @@epsilon) click to toggle source
# File lib/rgeoserver/utils/boundingbox.rb, line 75
def constrict rate = @@epsilon
  expand(-rate)
end
expand(rate = @@epsilon) click to toggle source
# File lib/rgeoserver/utils/boundingbox.rb, line 65
def expand rate = @@epsilon
  _minx, _miny = [minx - rate, miny - rate]
  _maxx, _maxy = [maxx + rate, maxy + rate]

  reset

  add _minx, _miny
  add _maxx, _maxy
end
height() click to toggle source
# File lib/rgeoserver/utils/boundingbox.rb, line 83
def height
  maxy - miny
end
inspect() click to toggle source
# File lib/rgeoserver/utils/boundingbox.rb, line 127
def inspect
  "#<#{self.class} #{to_s}>"
end
max() click to toggle source
# File lib/rgeoserver/utils/boundingbox.rb, line 61
def max
  [maxx, maxy]
end
min() click to toggle source
# File lib/rgeoserver/utils/boundingbox.rb, line 57
def min
  [minx, miny]
end
reset() click to toggle source
# File lib/rgeoserver/utils/boundingbox.rb, line 34
def reset
  @minx = @miny = @maxx = @maxy = 0.0
  @empty = true
end
to_a() click to toggle source
# File lib/rgeoserver/utils/boundingbox.rb, line 119
def to_a
  [minx, miny, maxx, maxy]
end
to_geometry() click to toggle source
# File lib/rgeoserver/utils/boundingbox.rb, line 96
def to_geometry
  factory = RGeo::Cartesian::Factory.new

  point_min, point_max = unless [minx, miny] == [maxx, maxy]
    [factory.point(minx, miny), factory.point(maxx, maxy)]
  else
    [factory.point(minx - @@epsilon, miny - @@epsilon),
     factory.point(maxx + @@epsilon, maxy + @@epsilon)]
  end

  line_string = factory.line_string [point_min, point_max]
  line_string.envelope
end
to_h() click to toggle source
# File lib/rgeoserver/utils/boundingbox.rb, line 110
def to_h
  {
    :minx => minx,
    :miny => miny,
    :maxx => maxx,
    :maxy => maxy
  }
end
to_s() click to toggle source
# File lib/rgeoserver/utils/boundingbox.rb, line 123
def to_s
  to_a.join(', ')
end
valid?() click to toggle source

@return true if bounding box has non-zero area

# File lib/rgeoserver/utils/boundingbox.rb, line 92
def valid?
  area > 0
end
width() click to toggle source
# File lib/rgeoserver/utils/boundingbox.rb, line 79
def width
  maxx - minx
end