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.
12 13 14 15 16 17 |
# File 'lib/geo_combine/bounding_box.rb', line 12 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.
5 6 7 |
# File 'lib/geo_combine/bounding_box.rb', line 5 def east @east end |
#north ⇒ Object (readonly)
Returns the value of attribute north.
5 6 7 |
# File 'lib/geo_combine/bounding_box.rb', line 5 def north @north end |
#south ⇒ Object (readonly)
Returns the value of attribute south.
5 6 7 |
# File 'lib/geo_combine/bounding_box.rb', line 5 def south @south end |
#west ⇒ Object (readonly)
Returns the value of attribute west.
5 6 7 |
# File 'lib/geo_combine/bounding_box.rb', line 5 def west @west end |
Class Method Details
.from_envelope(envelope) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/geo_combine/bounding_box.rb', line 50 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
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/geo_combine/bounding_box.rb', line 65 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
22 23 24 |
# File 'lib/geo_combine/bounding_box.rb', line 22 def to_envelope "ENVELOPE(#{west}, #{east}, #{north}, #{south})" end |
#valid? ⇒ Boolean
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/geo_combine/bounding_box.rb', line 26 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 |