Class: Stanford::Mods::Coordinate

Inherits:
Object
  • Object
show all
Defined in:
lib/stanford-mods/coordinate.rb

Overview

Geospatial coordinate parsing

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Coordinate

Returns a new instance of Coordinate.



9
10
11
# File 'lib/stanford-mods/coordinate.rb', line 9

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



7
8
9
# File 'lib/stanford-mods/coordinate.rb', line 7

def value
  @value
end

Instance Method Details

#as_bboxString

Returns the coordinate in Solr 4.x+ bbox-format representation.

Returns:

  • (String)

    the coordinate in Solr 4.x+ bbox-format representation



21
22
23
24
25
# File 'lib/stanford-mods/coordinate.rb', line 21

def as_bbox
  return unless valid?

  "#{bounds[:min_x]} #{bounds[:min_y]} #{bounds[:max_x]} #{bounds[:max_y]}"
end

#as_envelopeString

Returns the coordinate in WKT/CQL ENVELOPE representation.

Returns:

  • (String)

    the coordinate in WKT/CQL ENVELOPE representation



14
15
16
17
18
# File 'lib/stanford-mods/coordinate.rb', line 14

def as_envelope
  return unless valid?

  "ENVELOPE(#{bounds[:min_x]}, #{bounds[:max_x]}, #{bounds[:max_y]}, #{bounds[:min_y]})"
end

#valid?Boolean

Returns true iff the coordinates are geographically valid.

Returns:

  • (Boolean)

    true iff the coordinates are geographically valid



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/stanford-mods/coordinate.rb', line 28

def valid?
  return false if bounds.empty?

  range_x = -180.0..180.0
  range_y = -90.0..90.0

  range_x.include?(bounds[:min_x]) &&
    range_x.include?(bounds[:max_x]) &&
    range_y.include?(bounds[:min_y]) &&
    range_y.include?(bounds[:max_y])
end