Class: Geoblacklight::BoundingBox

Inherits:
Object
  • Object
show all
Defined in:
lib/geoblacklight/bounding_box.rb

Overview

Transforms and parses a bounding box for various formats

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(west, south, east, north) ⇒ BoundingBox

Returns a new instance of BoundingBox.

Parameters:

  • west (String, Integer, Float)
  • south (String, Integer, Float)
  • east (String, Integer, Float)
  • north (String, Integer, Float)


10
11
12
13
14
15
16
# File 'lib/geoblacklight/bounding_box.rb', line 10

def initialize(west, south, east, north)
  @west = west
  @south = south
  @east = east
  @north = north
  # TODO: check for valid Geometry and raise if not
end

Class Method Details

.from_rectangle(rectangle) ⇒ Geoblacklight::BoundingBox

Create a Geoblacklight::BoundingBox from a Solr rectangle syntax

Parameters:

  • bbox (String)

    as “W S E N”

Returns:



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/geoblacklight/bounding_box.rb', line 29

def self.from_rectangle(rectangle)
  rectangle_array = rectangle.split(' ')
  message = 'Bounding box should be a string in Solr rectangle syntax e.g."W S E N"'
  fail Geoblacklight::Exceptions::WrongBoundingBoxFormat, message if rectangle_array.count != 4
  new(
    rectangle_array[0],
    rectangle_array[1],
    rectangle_array[2],
    rectangle_array[3]
  )
end

Instance Method Details

#to_envelopeString

Returns a bounding box in ENVELOPE syntax

Returns:

  • (String)


21
22
23
# File 'lib/geoblacklight/bounding_box.rb', line 21

def to_envelope
  "ENVELOPE(#{west}, #{east}, #{north}, #{south})"
end