geoblacklight 0.10.0 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1ec7051ebc8d380e573700819f8dace0ca4c61b
4
- data.tar.gz: c903cc4bebe11b8502b502c056377e5b053b7f5b
3
+ metadata.gz: fb161150e767dc710a684cfc1b1ce58c50fdb432
4
+ data.tar.gz: 8d6fee0b74b5b103065a504f2d0e2c10d6ef0ee2
5
5
  SHA512:
6
- metadata.gz: 5ae9176ca20b2d55e9586ac3346bd9384a792feab18038068759d93fbf293e2438316b75bbad557c54dc9aaa7477ce30d75b691bbf83db450c38869f7685bed8
7
- data.tar.gz: 90a8a7f6d0836228781571d232aebd0b82c7eb5b114139abfd5a0509a10413dd1ef53b99b7ce322bf30a92bb2b08b2352808ead8ac550f601e3a860f86b79607
6
+ metadata.gz: 33ee645d8ed2522561f4fdc9614bde529c0ad3d02dbce805a0969f1427486222f63d874cb8070ac3e8661ebed69849999a8ebeadbd17457c0c2a4f7f2a4edfb1
7
+ data.tar.gz: 25d38f1a47e47bb05901a0720069a83266a5514c8797d69e1fff4bc65427539bada76dfe1dfa98c1ece3d073ee4539b3f021087dde7be74125b3f31d47d00b8b
@@ -1,6 +1,7 @@
1
1
  require "geoblacklight/engine"
2
2
 
3
3
  module Geoblacklight
4
+ require 'geoblacklight/bounding_box'
4
5
  require 'geoblacklight/catalog_helper_override'
5
6
  require 'geoblacklight/config'
6
7
  require 'geoblacklight/constants'
@@ -0,0 +1,44 @@
1
+ module Geoblacklight
2
+ ##
3
+ # Transforms and parses a bounding box for various formats
4
+ class BoundingBox
5
+ ##
6
+ # @param [String, Integer, Float] west
7
+ # @param [String, Integer, Float] south
8
+ # @param [String, Integer, Float] east
9
+ # @param [String, Integer, Float] north
10
+ def initialize(west, south, east, north)
11
+ @west = west
12
+ @south = south
13
+ @east = east
14
+ @north = north
15
+ # TODO: check for valid Geometry and raise if not
16
+ end
17
+
18
+ ##
19
+ # Returns a bounding box in ENVELOPE syntax
20
+ # @return [String]
21
+ def to_envelope
22
+ "ENVELOPE(#{west}, #{east}, #{north}, #{south})"
23
+ end
24
+
25
+ ##
26
+ # Create a Geoblacklight::BoundingBox from a Solr rectangle syntax
27
+ # @param [String] bbox as "W S E N"
28
+ # @return [Geoblacklight::BoundingBox]
29
+ def self.from_rectangle(rectangle)
30
+ rectangle_array = rectangle.split(' ')
31
+ fail Geoblacklight::Exceptions::WrongBoundingBoxFormat, 'Bounding box should be a string in Solr rectangle syntax e.g."W S E N"' if rectangle_array.count != 4
32
+ new(
33
+ rectangle_array[0],
34
+ rectangle_array[1],
35
+ rectangle_array[2],
36
+ rectangle_array[3]
37
+ )
38
+ end
39
+
40
+ private
41
+
42
+ attr_reader :west, :south, :east, :north
43
+ end
44
+ end
@@ -21,5 +21,7 @@ module Geoblacklight
21
21
  end
22
22
  class WrongDownloadFormat < StandardError
23
23
  end
24
+ class WrongBoundingBoxFormat < StandardError
25
+ end
24
26
  end
25
27
  end
@@ -7,14 +7,36 @@ module Geoblacklight
7
7
  @processor_chain += [:add_spatial_params] unless @processor_chain.include?(:add_spatial_params)
8
8
  end
9
9
 
10
+ ##
11
+ # Adds spatial parameters to a Solr query if :bbox is present.
12
+ # @param [Blacklight::Solr::Request] solr_params :bbox should be in Solr
13
+ # :bbox should be passed in using Solr lat-lon rectangle format e.g.
14
+ # "minX minY maxX maxY"
15
+ # @return [Blacklight::Solr::Request]
10
16
  def add_spatial_params(solr_params)
11
17
  if blacklight_params[:bbox]
12
18
  solr_params[:bq] ||= []
13
- solr_params[:bq] = ["#{Settings.GEOMETRY_FIELD}:\"IsWithin(#{blacklight_params[:bbox]})\"^10"]
19
+ solr_params[:bq] = ["#{Settings.GEOMETRY_FIELD}:\"IsWithin(#{envelope_bounds})\"^10"]
14
20
  solr_params[:fq] ||= []
15
- solr_params[:fq] << "#{Settings.GEOMETRY_FIELD}:\"Intersects(#{blacklight_params[:bbox]})\""
21
+ solr_params[:fq] << "#{Settings.GEOMETRY_FIELD}:\"Intersects(#{envelope_bounds})\""
16
22
  end
17
23
  solr_params
24
+ rescue Geoblacklight::Exceptions::WrongBoundingBoxFormat
25
+ # TODO: Potentially delete bbox params here so that its not rendered as search param
26
+ solr_params
27
+ end
28
+
29
+ ##
30
+ # @return [String]
31
+ def envelope_bounds
32
+ bounding_box.to_envelope
33
+ end
34
+
35
+ ##
36
+ # Returns a Geoblacklight::BoundingBox built from the blacklight_params
37
+ # @return [Geoblacklight::BoundingBox]
38
+ def bounding_box
39
+ Geoblacklight::BoundingBox.from_rectangle(blacklight_params[:bbox])
18
40
  end
19
41
  end
20
42
  end
@@ -1,3 +1,3 @@
1
1
  module Geoblacklight
2
- VERSION = '0.10.0'
2
+ VERSION = '0.10.1'
3
3
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  feature 'search bar' do
4
4
  scenario 'present on a spatial search' do
5
- visit catalog_index_path(bbox: '25, 3, 75, 35')
5
+ visit catalog_index_path(bbox: '25 3 75 35')
6
6
  expect(page).to have_css '#search-navbar'
7
7
  end
8
8
  scenario 'present on a text search' do
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Geoblacklight::BoundingBox do
4
+ describe '#initialize' do
5
+ it 'handles multiple input types as arguments' do
6
+ expect(Geoblacklight::BoundingBox.new('1', '1', '1', '1')).to be_an Geoblacklight::BoundingBox
7
+ expect(Geoblacklight::BoundingBox.new(1, 2, 3, 3)).to be_an Geoblacklight::BoundingBox
8
+ expect(Geoblacklight::BoundingBox.new(1.1, 2.1, 3.1, 3.1)).to be_an Geoblacklight::BoundingBox
9
+ end
10
+ end
11
+ describe '#to_envelope' do
12
+ let(:example_box) { Geoblacklight::BoundingBox.new(-160, -80, 120, 70) }
13
+ it 'creates an envelope syntax version of the bounding box' do
14
+ expect(example_box.to_envelope).to eq 'ENVELOPE(-160, 120, 70, -80)'
15
+ end
16
+ end
17
+ describe '#from_rectangle' do
18
+ let(:example_box) { Geoblacklight::BoundingBox.from_rectangle('-160 -80 120 70') }
19
+ it 'parses and creates a Geoblacklight::BoundingBox from a Solr lat-lon' do
20
+ expect(example_box).to be_an Geoblacklight::BoundingBox
21
+ expect(example_box.to_envelope).to eq 'ENVELOPE(-160, 120, 70, -80)'
22
+ end
23
+ it 'checks for valididity' do
24
+ expect { Geoblacklight::BoundingBox.from_rectangle('-160 -80 120') }.to raise_error Geoblacklight::Exceptions::WrongBoundingBoxFormat
25
+ end
26
+ end
27
+ end
@@ -36,10 +36,23 @@ describe Geoblacklight::SearchBuilder do
36
36
  end
37
37
 
38
38
  it 'should return a spatial search if bbox is given' do
39
- params = { :bbox => '123' }
39
+ params = { bbox: '-180 -80 120 80' }
40
40
  subject.with(params)
41
- expect(subject.add_spatial_params(solr_params)[:fq].to_s).to include("Intersects")
41
+ expect(subject.add_spatial_params(solr_params)[:fq].to_s).to include('Intersects')
42
+ end
43
+ end
44
+ describe '#envelope_bounds' do
45
+ it 'calls to_envelope on the bounding box' do
46
+ bbox = double('bbox', to_envelope: 'test')
47
+ expect(subject).to receive(:bounding_box).and_return bbox
48
+ expect(subject.envelope_bounds).to eq 'test'
49
+ end
50
+ end
51
+ describe '#bounding_box' do
52
+ it 'creates a bounding box from a Solr lat-lon rectangle format' do
53
+ params = { bbox: '-120 -80 120 80' }
54
+ subject.with(params)
55
+ expect(subject.bounding_box).to be_an Geoblacklight::BoundingBox
42
56
  end
43
57
  end
44
58
  end
45
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geoblacklight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Graves
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-05-18 00:00:00.000000000 Z
14
+ date: 2015-06-01 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: blacklight
@@ -343,6 +343,7 @@ files:
343
343
  - lib/generators/geoblacklight/templates/geoblacklight.js
344
344
  - lib/generators/geoblacklight/templates/settings.yml
345
345
  - lib/geoblacklight.rb
346
+ - lib/geoblacklight/bounding_box.rb
346
347
  - lib/geoblacklight/catalog_helper_override.rb
347
348
  - lib/geoblacklight/config.rb
348
349
  - lib/geoblacklight/constants.rb
@@ -395,6 +396,7 @@ files:
395
396
  - spec/fixtures/solr_documents/public_polygon_mit.json
396
397
  - spec/fixtures/solr_documents/restricted-line.json
397
398
  - spec/helpers/geoblacklight_helpers_spec.rb
399
+ - spec/lib/geoblacklight/bounding_box_spec.rb
398
400
  - spec/lib/geoblacklight/controller_override_spec.rb
399
401
  - spec/lib/geoblacklight/download/geojson_download_spec.rb
400
402
  - spec/lib/geoblacklight/download/geotiff_download_spec.rb
@@ -473,6 +475,7 @@ test_files:
473
475
  - spec/fixtures/solr_documents/public_polygon_mit.json
474
476
  - spec/fixtures/solr_documents/restricted-line.json
475
477
  - spec/helpers/geoblacklight_helpers_spec.rb
478
+ - spec/lib/geoblacklight/bounding_box_spec.rb
476
479
  - spec/lib/geoblacklight/controller_override_spec.rb
477
480
  - spec/lib/geoblacklight/download/geojson_download_spec.rb
478
481
  - spec/lib/geoblacklight/download/geotiff_download_spec.rb