Class: Stanford::Mods::Coordinate
- Inherits:
-
Object
- Object
- Stanford::Mods::Coordinate
- Includes:
- GeoUtils
- Defined in:
- lib/stanford-mods/coordinate.rb
Overview
Geospatial coordinate parsing
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#as_bbox ⇒ String
The coordinate in Solr 4.x+ bbox-format representation.
-
#as_envelope ⇒ String
The coordinate in WKT/CQL ENVELOPE representation.
-
#initialize(value) ⇒ Coordinate
constructor
A new instance of Coordinate.
-
#valid? ⇒ Boolean
True iff the coordinates are geographically valid.
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
#value ⇒ Object (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_bbox ⇒ String
Returns 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_envelope ⇒ String
Returns 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.
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 |