class GeoCombine::BoundingBox

Attributes

east[R]
north[R]
south[R]
west[R]

Public Class Methods

from_envelope(envelope) click to toggle source
# File lib/geo_combine/bounding_box.rb, line 46
def self.from_envelope(envelope)
  return if envelope.nil?
  envelope = envelope[/.*ENVELOPE\(([^\)]*)/, 1].split(',')
  new(
    west: envelope[0],
    south: envelope[3],
    east: envelope[1],
    north: envelope[2]
  )
end
from_string_delimiter(spatial, delimiter: ',') click to toggle source

@param [String] spatial w,s,e,n or w s e n @param [String] delimiter “,” or “ ”

# File lib/geo_combine/bounding_box.rb, line 60
def self.from_string_delimiter(spatial, delimiter: ',')
  return if spatial.nil?
  spatial = spatial.split(delimiter)
  new(
    west: spatial[0],
    south: spatial[1],
    east: spatial[2],
    north: spatial[3]
  )
end
new(west:, south:, east:, north:) click to toggle source

@param [String, Integer, Float] west @param [String, Integer, Float] south @param [String, Integer, Float] east @param [String, Integer, Float] north

# File lib/geo_combine/bounding_box.rb, line 10
def initialize(west:, south:, east:, north:)
  @west = west.to_f
  @south = south.to_f
  @east = east.to_f
  @north = north.to_f
end

Public Instance Methods

to_envelope() click to toggle source

Returns a bounding box in ENVELOPE syntax @return [String]

# File lib/geo_combine/bounding_box.rb, line 20
def to_envelope
  "ENVELOPE(#{west}, #{east}, #{north}, #{south})"
end
valid?() click to toggle source
# File lib/geo_combine/bounding_box.rb, line 24
def valid?
  [south, north].map do |coord|
    next if (-90..90).cover?(coord)
    raise GeoCombine::Exceptions::InvalidGeometry,
          "#{coord} should be in range -90 90"
  end
  [east, west].map do |coord|
    next if (-180..180).cover?(coord)
    raise GeoCombine::Exceptions::InvalidGeometry,
          "#{coord} should be in range -180 180"
  end
  if west > east
    raise GeoCombine::Exceptions::InvalidGeometry,
          "east #{east} should be greater than or equal to west #{west}"
  end
  if south > north
    raise GeoCombine::Exceptions::InvalidGeometry,
          "north #{north} should be greater than or equal to south #{south}"
  end
  true
end