Class: Stanford::Mods::Coordinate

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

Overview

Geospatial coordinate parsing

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GeoUtils

#cleaner_coordinate, #coord_to_decimal

Constructor Details

#initialize(value) ⇒ Coordinate

Returns a new instance of Coordinate.



12
13
14
# File 'lib/stanford-mods/coordinate.rb', line 12

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



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

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



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

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



17
18
19
20
# File 'lib/stanford-mods/coordinate.rb', line 17

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



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

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