Class: BlacklightHeatmaps::BoundingBox

Inherits:
Object
  • Object
show all
Defined in:
app/models/concerns/blacklight_heatmaps/bounding_box.rb

Overview

Used for creating and parsing bounding boxes from CQL Envelope syntax

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
# File 'app/models/concerns/blacklight_heatmaps/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

Class Method Details

.from_envelope(envelope) ⇒ Object



41
42
43
44
# File 'app/models/concerns/blacklight_heatmaps/bounding_box.rb', line 41

def self.from_envelope(envelope)
  envelope = envelope[/.*ENVELOPE\(([^\)]*)/,1].split(',')
  new(envelope[0], envelope[3], envelope[1], envelope[2])
end

Instance Method Details

#to_envelopeString

Returns a bounding box in ENVELOPE syntax

Returns:

  • (String)


20
21
22
# File 'app/models/concerns/blacklight_heatmaps/bounding_box.rb', line 20

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

#to_geojsonObject

Returns String.

Returns:

  • String



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/concerns/blacklight_heatmaps/bounding_box.rb', line 26

def to_geojson
{
  type: 'Polygon',
  coordinates: [
    [
      [west, south],
      [west, north],
      [east, north],
      [east, south],
      [west, south]
    ]
  ]
}.to_json
end