Class: CocinaDisplay::Geospatial::BoundingBox
- Inherits:
-
Coordinates
- Object
- Coordinates
- CocinaDisplay::Geospatial::BoundingBox
- Defined in:
- lib/cocina_display/geospatial.rb
Overview
A bounding box defined by two corner points.
Instance Attribute Summary collapse
-
#max_point ⇒ Object
readonly
Returns the value of attribute max_point.
-
#min_point ⇒ Object
readonly
Returns the value of attribute min_point.
Class Method Summary collapse
-
.from_coords(west:, east:, north:, south:) ⇒ BoundingBox?
Construct a BoundingBox from west, east, north, and south string values.
Instance Method Summary collapse
-
#as_envelope ⇒ String
Format using the CQL ENVELOPE representation.
-
#as_point ⇒ String
The box center point as a comma-separated latitude,longitude pair.
-
#as_wkt ⇒ String
Format using the Well-Known Text (WKT) representation.
-
#initialize(min_point:, max_point:) ⇒ BoundingBox
constructor
Construct a BoundingBox from two Geo::Coord points.
-
#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(min_point:, max_point:) ⇒ BoundingBox
Construct a BoundingBox from two Geo::Coord points.
165 166 167 168 |
# File 'lib/cocina_display/geospatial.rb', line 165 def initialize(min_point:, max_point:) @min_point = min_point @max_point = max_point end |
Instance Attribute Details
#max_point ⇒ Object (readonly)
Returns the value of attribute max_point.
144 145 146 |
# File 'lib/cocina_display/geospatial.rb', line 144 def max_point @max_point end |
#min_point ⇒ Object (readonly)
Returns the value of attribute min_point.
144 145 146 |
# File 'lib/cocina_display/geospatial.rb', line 144 def min_point @min_point end |
Class Method Details
.from_coords(west:, east:, north:, south:) ⇒ BoundingBox?
Construct a BoundingBox from west, east, north, and south string values.
152 153 154 155 156 157 158 159 160 |
# File 'lib/cocina_display/geospatial.rb', line 152 def self.from_coords(west:, east:, north:, south:) min_point = Geo::Coord.parse("#{north}, #{west}") max_point = Geo::Coord.parse("#{south}, #{east}") # Must be parsable return unless min_point && max_point new(min_point: min_point, max_point: max_point) end |
Instance Method Details
#as_envelope ⇒ String
Limits decimals to 6 places.
Format using the CQL ENVELOPE representation.
199 200 201 202 203 |
# File 'lib/cocina_display/geospatial.rb', line 199 def as_envelope "ENVELOPE(%.6f, %.6f, %.6f, %.6f)" % [ min_point.lng, max_point.lng, max_point.lat, min_point.lat ] end |
#as_point ⇒ String
Limits decimals to 6 places.
The box center point as a comma-separated latitude,longitude pair.
209 210 211 212 213 214 |
# File 'lib/cocina_display/geospatial.rb', line 209 def as_point azimuth = min_point.azimuth(max_point) distance = min_point.distance(max_point) center = min_point.endpoint(distance / 2, azimuth) "%.6f,%.6f" % [center.lat, center.lng] end |
#as_wkt ⇒ String
Limits decimals to 6 places.
Format using the Well-Known Text (WKT) representation.
185 186 187 188 189 190 191 192 193 |
# File 'lib/cocina_display/geospatial.rb', line 185 def as_wkt "POLYGON((%.6f %.6f, %.6f %.6f, %.6f %.6f, %.6f %.6f, %.6f %.6f))" % [ min_point.lng, min_point.lat, max_point.lng, min_point.lat, max_point.lng, max_point.lat, min_point.lng, max_point.lat, min_point.lng, min_point.lat ] end |
#to_s ⇒ String
This format adapts the “Annex D” human representation style.
Format for display in DMS format, adapted from ISO 6709 standard.
175 176 177 178 179 |
# File 'lib/cocina_display/geospatial.rb', line 175 def to_s min_lat, min_lng = format_point(min_point) max_lat, max_lng = format_point(max_point) "#{min_lng} -- #{max_lng} / #{min_lat} -- #{max_lat}" end |