Module: SearchSolrTools::Helpers::TranslateSpatialCoverage
- Defined in:
- lib/search_solr_tools/helpers/translate_spatial_coverage.rb
Overview
Methods to translate list of geoJson objects to solr format values
Class Method Summary collapse
- .convert_multipoint_to_point(spatial_coverage_geom) ⇒ Object
- .geojson_to_global_facet(spatial_coverage_geom) ⇒ Object
- .geojson_to_spatial_area(spatial_coverage_geom) ⇒ Object
- .geojson_to_spatial_display_str(spatial_coverage_geom) ⇒ Object
- .geojson_to_spatial_index_str(spatial_coverage_geom) ⇒ Object
- .geojson_to_spatial_scope_facet(spatial_coverage_geom) ⇒ Object
Class Method Details
.convert_multipoint_to_point(spatial_coverage_geom) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/search_solr_tools/helpers/translate_spatial_coverage.rb', line 19 def self.convert_multipoint_to_point(spatial_coverage_geom) return_geom = [] spatial_coverage_geom.each do |geom| if geom.geometry_type.to_s.downcase.eql?('multipoint') geom.each do |point| return_geom << point end else return_geom << geom end end return_geom end |
.geojson_to_global_facet(spatial_coverage_geom) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/search_solr_tools/helpers/translate_spatial_coverage.rb', line 59 def self.geojson_to_global_facet(spatial_coverage_geom) return nil if spatial_coverage_geom.nil? spatial_coverage_geom.each do |geo_json| bbox_hash = BoundingBoxUtil.bounding_box_hash_from_geo_json(geo_json) return 'Show Global Only' if BoundingBoxUtil.box_global?(bbox_hash) end nil end |
.geojson_to_spatial_area(spatial_coverage_geom) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/search_solr_tools/helpers/translate_spatial_coverage.rb', line 45 def self.geojson_to_spatial_area(spatial_coverage_geom) spatial_areas = spatial_coverage_geom.map do |geo_json| if %w[point].include?(geo_json.geometry_type.to_s.downcase) 0.0 else bbox = RGeo::Cartesian::BoundingBox.create_from_geometry(geo_json) bbox.max_y - bbox.min_y end end return nil if spatial_areas.empty? spatial_areas.max end |
.geojson_to_spatial_display_str(spatial_coverage_geom) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/search_solr_tools/helpers/translate_spatial_coverage.rb', line 11 def self.geojson_to_spatial_display_str(spatial_coverage_geom) spatial_coverage_geom = convert_multipoint_to_point(spatial_coverage_geom) spatial_coverage_geom.map do |geom| bbox = RGeo::Cartesian::BoundingBox.create_from_geometry(geom) "#{bbox.min_y} #{bbox.min_x} #{bbox.max_y} #{bbox.max_x}" end end |
.geojson_to_spatial_index_str(spatial_coverage_geom) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/search_solr_tools/helpers/translate_spatial_coverage.rb', line 33 def self.geojson_to_spatial_index_str(spatial_coverage_geom) spatial_coverage_geom = convert_multipoint_to_point(spatial_coverage_geom) spatial_coverage_geom.map do |geo_json| if geo_json.geometry_type.to_s.downcase.eql?('point') "#{geo_json.x} #{geo_json.y}" else bbox = RGeo::Cartesian::BoundingBox.create_from_geometry(geo_json) "ENVELOPE(#{bbox.min_x}, #{bbox.max_x}, #{bbox.max_y}, #{bbox.min_y})" end end end |
.geojson_to_spatial_scope_facet(spatial_coverage_geom) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/search_solr_tools/helpers/translate_spatial_coverage.rb', line 69 def self.geojson_to_spatial_scope_facet(spatial_coverage_geom) return if spatial_coverage_geom.nil? spatial_coverage_geom.map do |geo_json| bbox_hash = BoundingBoxUtil.bounding_box_hash_from_geo_json(geo_json) scope = SolrFormat.get_spatial_scope_facet_with_bounding_box(bbox_hash) scope unless scope.nil? end.uniq end |