geo_works 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f0533a41de0604673a4376d3597656459ecbbaf9
4
- data.tar.gz: 4c0f1211b8313e5c5531d37152ce9332b9b2e50d
3
+ metadata.gz: bb061d01830fb5921dd128e5a1c8aae57828d706
4
+ data.tar.gz: 25df64e996fe4bf08d07ef03e9d1c873c53d75f1
5
5
  SHA512:
6
- metadata.gz: 32233c2443c74edd7eece43f1558a399fb4444527cf7df4bac7658b0ea877257a1beb22807d10328ac54b8b672628d77472b5a7ee28174837aa6e3628fa85e5b
7
- data.tar.gz: 37fe03c153f448b27fb28522eb98d92ffb5eea0b44e4d90b13120efcbb34510478408ca8976a9ce33582454a8f27c4f3a7ff79f825629caa1a670686f9c43d0d
6
+ metadata.gz: b92710175c86f0a448d8a9b791baaef368ddac96ef5e7b6b44390c471b187eec522f468a03e1f92bfc3cdb610ae45c748fea74983874a2e33c66ecaf3cdcd7e7
7
+ data.tar.gz: 182c7c85c84d908bcab4938d792e7a37daf0d9e2694d4b3fb5dc92959ceb64c8e1b39277b7f0b5282a21739e6c89e07ca84637867c99f74804afcb4c4eff1dbb
@@ -0,0 +1,7 @@
1
+ module GeoWorks
2
+ module GeoFileSetHelper
3
+ def file_set_geometry(presenter)
4
+ presenter.solr_document.fetch(Solrizer.solr_name('geometry_type'), ['']).first
5
+ end
6
+ end
7
+ end
@@ -64,7 +64,9 @@ module GeoWorks
64
64
  # @return [String] vector geom
65
65
  def vector_geom
66
66
  match = /(?<=Geometry:\s).*?(?=\n)/.match(doc)
67
- match ? match[0] : ''
67
+ geom = match ? match[0] : ''
68
+ # Transform OGR-style 'Line String' into GeoJSON 'Line'
69
+ geom == 'Line String' ? 'Line' : geom
68
70
  end
69
71
 
70
72
  # Given an output string from the ogrinfo command, returns
@@ -1,5 +1,6 @@
1
1
  module GeoWorks
2
2
  class FileSetMetadataRequired < ActiveTriples::Schema
3
3
  property :geo_mime_type, predicate: RDF::Vocab::EBUCore.hasMimeType, multiple: false
4
+ property :geometry_type, predicate: RDF::Vocab::GEOJSON.type, multiple: false
4
5
  end
5
6
  end
@@ -46,19 +46,26 @@ module GeoWorks
46
46
  # Returns the geometry for a vector file.
47
47
  # @return [String] vector geometry
48
48
  def vector_geom_type
49
- # TODO: Get the geom type as part of a geo characterization service.
50
- # "Point, Line, Polygon, Mixed"
51
- 'Mixed'
49
+ return 'Mixed' if file_sets.nil? || file_sets.empty?
50
+ geom_field = Solrizer.solr_name('geometry_type')
51
+ file_sets.first.solr_document.fetch(geom_field, ['Mixed']).first
52
52
  end
53
53
 
54
54
  # Returns the 'geo' mime type of the first file attached to the work.
55
55
  # @return [String] file mime type
56
56
  def geo_mime_type
57
- file_sets = geo_concern.geo_file_set_presenters
58
57
  return if file_sets.nil? || file_sets.empty?
59
58
  return unless (mime_types = file_sets.first.solr_document[:geo_mime_type_ssim])
60
59
  mime_types.first
61
60
  end
61
+
62
+ # Gets geo file set presenters.
63
+ # @return [FileSet] geo file sets
64
+ def file_sets
65
+ @file_sets ||= begin
66
+ geo_concern.geo_file_set_presenters
67
+ end
68
+ end
62
69
  end
63
70
  end
64
71
  end
@@ -17,6 +17,7 @@ module GeoWorks
17
17
  create_raster_derivatives(filename)
18
18
  when *GeoWorks::VectorFormatService.select_options.map(&:last)
19
19
  create_vector_derivatives(filename)
20
+ GeoWorks::VectorGeometryService.new(file_set, derivative_url('display_vector')).call
20
21
  end
21
22
 
22
23
  # Once all the derivatives are created, send a created message
@@ -0,0 +1,31 @@
1
+ module GeoWorks
2
+ class VectorGeometryService
3
+ attr_reader :file_set, :file_path
4
+
5
+ def initialize(file_set, file_path)
6
+ @file_set = file_set
7
+ @file_path = file_path.gsub('file:', '')
8
+ end
9
+
10
+ # Extracts geometry type from display vector and saves value in FileSet.
11
+ def call
12
+ file_set.geometry_type = geometry
13
+ file_set.save!
14
+ end
15
+
16
+ private
17
+
18
+ def geometry
19
+ unzip_display_vector
20
+ GeoWorks::Processors::Vector::Info.new(shapefile_dir).geom
21
+ end
22
+
23
+ def shapefile_dir
24
+ "#{File.dirname(file_path)}/#{File.basename(file_path, '.zip')}"
25
+ end
26
+
27
+ def unzip_display_vector
28
+ system "unzip -o #{file_path} -d #{shapefile_dir}" unless File.directory?(shapefile_dir)
29
+ end
30
+ end
31
+ end
@@ -4,6 +4,7 @@
4
4
  </td>
5
5
  <td class="attribute filename"><%= link_to(member.link_name, main_app.hyrax_file_set_path(member)) %></td>
6
6
  <td class="attribute date_uploaded"><%= member.date_uploaded %></td>
7
+ <td class="attribute geometry"><%= file_set_geometry(member) %></td>
7
8
  <td class="attribute permission"><%= member.permission_badge %></td>
8
9
  <td>
9
10
  <%= file_set_actions(member) %>
@@ -9,6 +9,7 @@
9
9
  <th>File</th>
10
10
  <th>Filename</th>
11
11
  <th>Date Uploaded</th>
12
+ <th>Geometry</th>
12
13
  <th>Visibility</th>
13
14
  <th>Actions</th>
14
15
  </tr>
@@ -1,3 +1,3 @@
1
1
  module GeoWorks
2
- VERSION = "0.1.4".freeze
2
+ VERSION = "0.2.0".freeze
3
3
  end
@@ -9,10 +9,11 @@ describe "display a vector work as its owner", type: :feature do
9
9
  let(:attributes) { { title: title, coverage: coverage, spatial: spatial, temporal: temporal, user: user } }
10
10
  let(:fgdc_file) { test_data_fixture_path('zipcodes_fgdc.xml') }
11
11
  let(:vector_file) { test_data_fixture_path('files/tufts-cambridgegrid100-04.zip') }
12
+ let(:generator) { instance_double(GeoWorks::EventsGenerator).as_null_object }
12
13
 
13
14
  before do
14
- allow(GeoblacklightJob).to receive(:perform_later)
15
- allow(CharacterizeJob).to receive(:perform_later)
15
+ allow(GeoWorks::EventsGenerator).to receive(:new).and_return(generator)
16
+ allow(Hydra::Works::CharacterizationService).to receive(:run)
16
17
  create(:sipity_entity, proxy_for_global_id: work.to_global_id.to_s)
17
18
  end
18
19
 
@@ -33,29 +34,40 @@ describe "display a vector work as its owner", type: :feature do
33
34
  expect(page).to have_css("input#work_parent_members_ids")
34
35
  end
35
36
 
36
- it "allows the user to attach files and extract attributes from metadata file" do
37
- click_button 'Attach File'
38
- click_link 'Attach Vector'
39
- fill_in 'file_set[title][]', with: 'Vector File'
40
- select 'ESRI Shapefile', from: 'file_set_geo_mime_type'
41
- attach_file 'file_set[files][]', vector_file
42
- click_button 'Attach to Vector Work'
43
- expect(page).to have_text 'Vector File'
44
- expect(page).to have_selector(:link_or_button, 'Download')
45
-
46
- click_button 'Attach File'
47
- click_link 'Attach Metadata'
48
- fill_in 'file_set[title][]', with: 'Metadata File'
49
- select 'FGDC', from: 'file_set_geo_mime_type'
50
- attach_file 'file_set[files][]', fgdc_file
51
- click_button 'Attach to Vector Work'
52
- expect(page).to have_text 'Metadata File'
53
-
54
- click_link 'Edit Work'
55
- select 'zipcodes_fgdc.xml', from: 'vector_work[should_populate_metadata]'
56
- click_button 'Save'
57
- click_link "No. I'll update it manually."
58
- expect(page).to have_text 'Louisiana ZIP Code Areas 2002'
37
+ context 'when attaching files' do
38
+ after do
39
+ # Clean up derivatives
40
+ work_presenter = GeoWorks::VectorWorkShowPresenter.new(work, nil)
41
+ file_set = work_presenter.geo_file_set_presenters.first
42
+ dir = File.join(Hyrax.config.derivatives_path, file_set.id[0..1])
43
+ FileUtils.rm_r(dir) if File.directory?(dir)
44
+ end
45
+
46
+ it "allows the user to attach files and extract attributes from metadata file" do
47
+ click_button 'Attach File'
48
+ click_link 'Attach Vector'
49
+ fill_in 'file_set[title][]', with: 'Vector File'
50
+ select 'ESRI Shapefile', from: 'file_set_geo_mime_type'
51
+ attach_file 'file_set[files][]', vector_file
52
+ click_button 'Attach to Vector Work'
53
+ expect(page).to have_text 'Vector File'
54
+ expect(page).to have_selector(:link_or_button, 'Download')
55
+ expect(page).to have_text 'Polygon'
56
+
57
+ click_button 'Attach File'
58
+ click_link 'Attach Metadata'
59
+ fill_in 'file_set[title][]', with: 'Metadata File'
60
+ select 'FGDC', from: 'file_set_geo_mime_type'
61
+ attach_file 'file_set[files][]', fgdc_file
62
+ click_button 'Attach to Vector Work'
63
+ expect(page).to have_text 'Metadata File'
64
+
65
+ click_link 'Edit Work'
66
+ select 'zipcodes_fgdc.xml', from: 'vector_work[should_populate_metadata]'
67
+ click_button 'Save'
68
+ click_link "No. I'll update it manually."
69
+ expect(page).to have_text 'Louisiana ZIP Code Areas 2002'
70
+ end
59
71
  end
60
72
  end
61
73
  end
@@ -26,13 +26,17 @@ end
26
26
 
27
27
  shared_examples 'a set of vector derivatives' do
28
28
  let(:generator) { instance_double(GeoWorks::EventsGenerator) }
29
+ let(:geometry_service) { instance_double(GeoWorks::VectorGeometryService) }
30
+
29
31
  before do
30
32
  allow(GeoWorks::EventsGenerator).to receive(:new).and_return(generator)
33
+ allow(GeoWorks::VectorGeometryService).to receive(:new).and_return(geometry_service)
31
34
  allow(generator).to receive(:derivatives_created)
32
35
  end
33
36
  it 'makes a thumbnail' do
34
37
  new_thumb = "#{Rails.root}/tmp/derivatives/#{file_set.id}/thumbnail.thumbnail"
35
38
  expect(generator).to receive(:derivatives_created).with(file_set)
39
+ expect(geometry_service).to receive(:call)
36
40
  expect {
37
41
  file_set.create_derivatives(file_name)
38
42
  }.to change { Dir[new_thumb].empty? }
@@ -41,6 +45,7 @@ shared_examples 'a set of vector derivatives' do
41
45
 
42
46
  it 'makes a display vector' do
43
47
  new_thumb = "#{Rails.root}/tmp/derivatives/#{file_set.id}/display_vector.display_vector"
48
+ expect(geometry_service).to receive(:call)
44
49
  expect {
45
50
  file_set.create_derivatives(file_name)
46
51
  }.to change { Dir[new_thumb].empty? }
@@ -3,21 +3,22 @@ require 'open3'
3
3
 
4
4
  describe GeoWorks::Processors::Vector::Info do
5
5
  let(:path) { 'test.tif' }
6
- let(:info_doc) { read_test_data_fixture('ogrinfo.txt') }
6
+ let(:polygon_info_doc) { read_test_data_fixture('ogrinfo_polygon.txt') }
7
+ let(:line_info_doc) { read_test_data_fixture('ogrinfo_line.txt') }
7
8
 
8
9
  subject { described_class.new(path) }
9
10
 
10
11
  context 'when initializing a new info class' do
11
12
  it 'shells out to ogrinfo and sets the doc variable to the output string' do
12
13
  expect(Open3).to receive(:capture3).with("ogrinfo -ro -so -al #{path}")
13
- .and_return([info_doc, '', ''])
14
- expect(subject.doc).to eq(info_doc)
14
+ .and_return([polygon_info_doc, '', ''])
15
+ expect(subject.doc).to eq(polygon_info_doc)
15
16
  end
16
17
  end
17
18
 
18
- context 'after intialization' do
19
+ context 'with a polygon vector' do
19
20
  before do
20
- allow(subject).to receive(:doc).and_return(info_doc)
21
+ allow(subject).to receive(:doc).and_return(polygon_info_doc)
21
22
  end
22
23
 
23
24
  describe '#name' do
@@ -33,7 +34,7 @@ describe GeoWorks::Processors::Vector::Info do
33
34
  end
34
35
 
35
36
  describe '#geom' do
36
- it 'returns raster size' do
37
+ it 'returns vector geometry' do
37
38
  expect(subject.geom).to eq('Polygon')
38
39
  end
39
40
  end
@@ -47,4 +48,16 @@ describe GeoWorks::Processors::Vector::Info do
47
48
  end
48
49
  end
49
50
  end
51
+
52
+ context 'with a line vector' do
53
+ before do
54
+ allow(subject).to receive(:doc).and_return(line_info_doc)
55
+ end
56
+
57
+ describe '#geom' do
58
+ it 'returns vector geometry' do
59
+ expect(subject.geom).to eq('Line')
60
+ end
61
+ end
62
+ end
50
63
  end
@@ -14,7 +14,7 @@ describe GeoWorks::Discovery::DocumentBuilder do
14
14
  let(:metadata_file) { FileSet.new(id: 'metadatafile', geo_mime_type: metadata__mime_type) }
15
15
  let(:metadata_presenter) { Hyrax::FileSetPresenter.new(SolrDocument.new(metadata_file.to_solr), nil) }
16
16
  let(:geo_file_mime_type) { 'application/zip; ogr-format="ESRI Shapefile"' }
17
- let(:geo_file) { FileSet.new(id: 'geofile', geo_mime_type: geo_file_mime_type) }
17
+ let(:geo_file) { FileSet.new(id: 'geofile', geo_mime_type: geo_file_mime_type, geometry_type: 'Line') }
18
18
  let(:geo_file_presenter) { Hyrax::FileSetPresenter.new(SolrDocument.new(geo_file.to_solr), nil) }
19
19
  let(:coverage) { GeoWorks::Coverage.new(43.039, -69.856, 42.943, -71.032) }
20
20
  let(:issued) { '01/02/2013' }
@@ -83,7 +83,7 @@ describe GeoWorks::Discovery::DocumentBuilder do
83
83
  end
84
84
 
85
85
  it 'has layer info fields' do
86
- expect(document['layer_geom_type_s']).to eq('Mixed')
86
+ expect(document['layer_geom_type_s']).to eq('Line')
87
87
  expect(document['dc_format_s']).to eq('Shapefile')
88
88
  end
89
89
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geo_works
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Griffin
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2017-09-06 00:00:00.000000000 Z
15
+ date: 2017-09-13 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: hyrax
@@ -386,6 +386,7 @@ files:
386
386
  - app/helpers/geo_works/application_helper.rb
387
387
  - app/helpers/geo_works/bounding_box_helper.rb
388
388
  - app/helpers/geo_works/file_set_actions_helper.rb
389
+ - app/helpers/geo_works/geo_file_set_helper.rb
389
390
  - app/helpers/geo_works/geo_works_helper.rb
390
391
  - app/helpers/geo_works/populate_metadata_helper.rb
391
392
  - app/jobs/geoblacklight_job.rb
@@ -466,6 +467,7 @@ files:
466
467
  - app/services/geo_works/metadata_format_service.rb
467
468
  - app/services/geo_works/raster_format_service.rb
468
469
  - app/services/geo_works/vector_format_service.rb
470
+ - app/services/geo_works/vector_geometry_service.rb
469
471
  - app/services/hyrax/curation_concern.rb
470
472
  - app/values/geo_works/coverage.rb
471
473
  - app/values/geo_works/time_period.rb