Module: SearchSolrTools::Helpers::BoundingBoxUtil
- Defined in:
- lib/search_solr_tools/helpers/bounding_box_util.rb
Overview
Utility methods for dealing with bounding boxes.
Constant Summary collapse
- SOUTHERN_GLOBAL_BOUNDARY =
-85.0
- NORTHERN_GLOBAL_BOUNDARY =
85.0
Class Method Summary collapse
- .bounding_box_hash_from_geo_json(geometry) ⇒ Object
- .box_global?(box) ⇒ Boolean
- .box_invalid?(box) ⇒ Boolean
- .box_local?(box) ⇒ Boolean
- .geometry_is_point?(geometry) ⇒ Boolean
Class Method Details
.bounding_box_hash_from_geo_json(geometry) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/search_solr_tools/helpers/bounding_box_util.rb', line 12 def self.bounding_box_hash_from_geo_json(geometry) return { west: geometry.x.to_s, south: geometry.y.to_s, east: geometry.x.to_s, north: geometry.y.to_s } if geometry_is_point?(geometry) bbox = RGeo::Cartesian::BoundingBox.create_from_geometry(geometry) { west: bbox.min_x.to_s, south: bbox.min_y.to_s, east: bbox.max_x.to_s, north: bbox.max_y.to_s } end |
.box_global?(box) ⇒ Boolean
23 24 25 |
# File 'lib/search_solr_tools/helpers/bounding_box_util.rb', line 23 def self.box_global?(box) box[:south].to_f < SOUTHERN_GLOBAL_BOUNDARY && box[:north].to_f > NORTHERN_GLOBAL_BOUNDARY end |
.box_invalid?(box) ⇒ Boolean
32 33 34 |
# File 'lib/search_solr_tools/helpers/bounding_box_util.rb', line 32 def self.box_invalid?(box) %i[north south east west].any? { |d| box[d].to_s.empty? } end |
.box_local?(box) ⇒ Boolean
27 28 29 30 |
# File 'lib/search_solr_tools/helpers/bounding_box_util.rb', line 27 def self.box_local?(box) distance = box[:north].to_f - box[:south].to_f distance < 1 end |
.geometry_is_point?(geometry) ⇒ Boolean
19 20 21 |
# File 'lib/search_solr_tools/helpers/bounding_box_util.rb', line 19 def self.geometry_is_point?(geometry) geometry.geometry_type.to_s.downcase.eql?('point') end |