Class: GeoCombine::BoundingBox
- Inherits:
-
Object
- Object
- GeoCombine::BoundingBox
- Defined in:
- lib/geo_combine/bounding_box.rb
Instance Attribute Summary collapse
-
#east ⇒ Object
readonly
Returns the value of attribute east.
-
#north ⇒ Object
readonly
Returns the value of attribute north.
-
#south ⇒ Object
readonly
Returns the value of attribute south.
-
#west ⇒ Object
readonly
Returns the value of attribute west.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(west:, south:, east:, north:) ⇒ BoundingBox
constructor
A new instance of BoundingBox.
-
#to_envelope ⇒ String
Returns a bounding box in ENVELOPE syntax.
- #valid? ⇒ Boolean
Constructor Details
#initialize(west:, south:, east:, north:) ⇒ BoundingBox
Returns a new instance of BoundingBox.
10 11 12 13 14 15 |
# 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 |
Instance Attribute Details
#east ⇒ Object (readonly)
Returns the value of attribute east.
3 4 5 |
# File 'lib/geo_combine/bounding_box.rb', line 3 def east @east end |
#north ⇒ Object (readonly)
Returns the value of attribute north.
3 4 5 |
# File 'lib/geo_combine/bounding_box.rb', line 3 def north @north end |
#south ⇒ Object (readonly)
Returns the value of attribute south.
3 4 5 |
# File 'lib/geo_combine/bounding_box.rb', line 3 def south @south end |
#west ⇒ Object (readonly)
Returns the value of attribute west.
3 4 5 |
# File 'lib/geo_combine/bounding_box.rb', line 3 def west @west end |
Class Method Details
.from_envelope(envelope) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# 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: ',') ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# 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 |
Instance Method Details
#to_envelope ⇒ String
Returns a bounding box in ENVELOPE syntax
20 21 22 |
# File 'lib/geo_combine/bounding_box.rb', line 20 def to_envelope "ENVELOPE(#{west}, #{east}, #{north}, #{south})" end |
#valid? ⇒ Boolean
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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 |