Class: BlacklightMaps::Geometry::BoundingBox
- Inherits:
-
Object
- Object
- BlacklightMaps::Geometry::BoundingBox
- Defined in:
- lib/blacklight/maps/geometry.rb
Overview
This class contains Bounding Box objects and methods for interacting with them.
Class Method Summary collapse
-
.from_lon_lat_string(points) ⇒ Object
Creates a new bounding box from from a string of points “-100 -50 100 50” (south west north east).
-
.from_wkt_envelope(envelope) ⇒ Object
Creates a new bounding box from from a Solr WKT Envelope string “ENVELOPE(34.26, 35.89, 33.33, 29.47)” (minX, maxX, maxY, minY).
Instance Method Summary collapse
-
#find_center ⇒ Object
Returns an array [lng, lat] which is the centerpoint of a BoundingBox.
- #geojson_geometry_array ⇒ Object
-
#initialize(points) ⇒ BoundingBox
constructor
points is an array containing longitude and latitude values which relate to the southwest and northeast points of a bounding box [west, south, east, north] ([minX, minY, maxX, maxY]).
- #to_a ⇒ Object
Constructor Details
#initialize(points) ⇒ BoundingBox
points is an array containing longitude and latitude values which relate to the southwest and northeast points of a bounding box
- west, south, east, north
-
([minX, minY, maxX, maxY]).
12 13 14 15 16 17 |
# File 'lib/blacklight/maps/geometry.rb', line 12 def initialize(points) @west = points[0].to_f @south = points[1].to_f @east = points[2].to_f @north = points[3].to_f end |
Class Method Details
.from_lon_lat_string(points) ⇒ Object
Creates a new bounding box from from a string of points “-100 -50 100 50” (south west north east)
42 43 44 |
# File 'lib/blacklight/maps/geometry.rb', line 42 def self.from_lon_lat_string(points) new(points.split(' ')) end |
.from_wkt_envelope(envelope) ⇒ Object
Creates a new bounding box from from a Solr WKT Envelope string “ENVELOPE(34.26, 35.89, 33.33, 29.47)” (minX, maxX, maxY, minY)
48 49 50 51 |
# File 'lib/blacklight/maps/geometry.rb', line 48 def self.from_wkt_envelope(envelope) coords = envelope.gsub(/[[A-Z]\(\)]/, '')&.split(', ') new([coords[0], coords[3], coords[1], coords[2]]) end |
Instance Method Details
#find_center ⇒ Object
Returns an array [lng, lat] which is the centerpoint of a BoundingBox.
32 33 34 35 36 37 38 |
# File 'lib/blacklight/maps/geometry.rb', line 32 def find_center center = [] center[0] = (@west + @east) / 2 center[1] = (@south + @north) / 2 center[0] -= 180 if @west > @east # handle bboxes that cross the dateline center end |
#geojson_geometry_array ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/blacklight/maps/geometry.rb', line 19 def geojson_geometry_array [ [ [@west, @south], [@east, @south], [@east, @north], [@west, @north], [@west, @south] ] ] end |
#to_a ⇒ Object
53 54 55 |
# File 'lib/blacklight/maps/geometry.rb', line 53 def to_a [@west, @south, @east, @north] end |