module SearchSolrTools::Helpers::BoundingBoxUtil
Utility methods for dealing with bounding boxes.
Constants
- NORTHERN_GLOBAL_BOUNDARY
- SOUTHERN_GLOBAL_BOUNDARY
Public Class Methods
bounding_box_hash_from_geo_json(geometry)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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