Class: CocinaDisplay::Geospatial::Point
- Inherits:
-
Coordinates
- Object
- Coordinates
- CocinaDisplay::Geospatial::Point
- Defined in:
- lib/cocina_display/geospatial.rb
Overview
A single geospatial point with latitude and longitude.
Instance Attribute Summary collapse
-
#point ⇒ Object
readonly
Returns the value of attribute point.
Class Method Summary collapse
-
.from_coords(lat:, lng:) ⇒ Point?
Construct a Point from latitude and longitude string values.
Instance Method Summary collapse
-
#as_envelope ⇒ nil
Format using the CQL ENVELOPE representation.
-
#as_point ⇒ String
Format as a comma-separated latitude,longitude pair.
-
#as_wkt ⇒ String
Format using the Well-Known Text (WKT) representation.
-
#initialize(point) ⇒ Point
constructor
Construct a Point from a single Geo::Coord point.
-
#to_s ⇒ String
Format for display in DMS format, adapted from ISO 6709 standard.
Methods inherited from Coordinates
from_cocina, from_structured_values, parse
Constructor Details
#initialize(point) ⇒ Point
Construct a Point from a single Geo::Coord point.
104 105 106 |
# File 'lib/cocina_display/geospatial.rb', line 104 def initialize(point) @point = point end |
Instance Attribute Details
#point ⇒ Object (readonly)
Returns the value of attribute point.
89 90 91 |
# File 'lib/cocina_display/geospatial.rb', line 89 def point @point end |
Class Method Details
.from_coords(lat:, lng:) ⇒ Point?
Construct a Point from latitude and longitude string values.
95 96 97 98 99 100 |
# File 'lib/cocina_display/geospatial.rb', line 95 def self.from_coords(lat:, lng:) point = Geo::Coord.parse("#{lat}, #{lng}") return unless point new(point) end |
Instance Method Details
#as_envelope ⇒ nil
This is impossible for a single point; we always return nil.
Format using the CQL ENVELOPE representation.
129 130 131 |
# File 'lib/cocina_display/geospatial.rb', line 129 def as_envelope nil end |
#as_point ⇒ String
Limits decimals to 6 places.
Format as a comma-separated latitude,longitude pair.
137 138 139 |
# File 'lib/cocina_display/geospatial.rb', line 137 def as_point "%.6f,%.6f" % [point.lat, point.lng] end |
#as_wkt ⇒ String
Limits decimals to 6 places.
Format using the Well-Known Text (WKT) representation.
122 123 124 |
# File 'lib/cocina_display/geospatial.rb', line 122 def as_wkt "POINT(%.6f %.6f)" % [point.lat, point.lng] end |
#to_s ⇒ String
This format adapts the “Annex D” human representation style.
Format for display in DMS format, adapted from ISO 6709 standard.
113 114 115 |
# File 'lib/cocina_display/geospatial.rb', line 113 def to_s format_point(point).join(" ") end |