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)


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

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:



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/geoblacklight/bounding_box.rb', line 35

def self.from_rectangle(rectangle)
  rectangle_array = rectangle.is_a?(String) ? 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)


23
24
25
# File 'lib/geoblacklight/bounding_box.rb', line 23

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

#to_paramObject



27
28
29
# File 'lib/geoblacklight/bounding_box.rb', line 27

def to_param
  "#{west} #{south} #{east} #{north}"
end