geo_concerns 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.rubocop.yml +101 -0
  4. data/.travis.yml +17 -0
  5. data/Gemfile +46 -0
  6. data/LICENSE +202 -0
  7. data/README.md +46 -0
  8. data/Rakefile +21 -0
  9. data/app/actors/geo_concerns/file_actor.rb +20 -0
  10. data/app/actors/geo_concerns/file_set_actor.rb +7 -0
  11. data/app/assets/images/geo_concerns/.keep +0 -0
  12. data/app/assets/images/geo_concerns/images/geocoder.png +0 -0
  13. data/app/assets/images/geo_concerns/images/throbber.gif +0 -0
  14. data/app/assets/images/geo_concerns/img/filter-icon.png +0 -0
  15. data/app/assets/images/geo_concerns/img/move-handle.png +0 -0
  16. data/app/assets/images/geo_concerns/img/resize-handle.png +0 -0
  17. data/app/assets/javascripts/geo_concerns/Control.Geocoder.js +1056 -0
  18. data/app/assets/javascripts/geo_concerns/application.js +5 -0
  19. data/app/assets/javascripts/geo_concerns/bounding_box_selector.js +100 -0
  20. data/app/assets/javascripts/geo_concerns/leaflet-boundingbox.js +467 -0
  21. data/app/assets/stylesheets/geo_concerns/Control.Geocoder.css +104 -0
  22. data/app/assets/stylesheets/geo_concerns/application.css +18 -0
  23. data/app/assets/stylesheets/geo_concerns/bounding_box.scss +7 -0
  24. data/app/assets/stylesheets/geo_concerns/leaflet-boundingbox.css +17 -0
  25. data/app/controllers/concerns/geo_concerns/file_sets_controller_behavior.rb +19 -0
  26. data/app/controllers/concerns/geo_concerns/image_works_controller_behavior.rb +13 -0
  27. data/app/controllers/concerns/geo_concerns/raster_works_controller_behavior.rb +23 -0
  28. data/app/controllers/concerns/geo_concerns/vector_works_controller_behavior.rb +23 -0
  29. data/app/forms/geo_concerns/basic_geo_metadata_form.rb +8 -0
  30. data/app/forms/geo_concerns/external_metadata_file_form.rb +8 -0
  31. data/app/forms/geo_concerns/georeferenced_form.rb +9 -0
  32. data/app/forms/geo_concerns/image_work_form.rb +9 -0
  33. data/app/forms/geo_concerns/raster_work_form.rb +8 -0
  34. data/app/forms/geo_concerns/vector_work_form.rb +8 -0
  35. data/app/helpers/bounding_box_helper.rb +24 -0
  36. data/app/helpers/geo_concerns/application_helper.rb +4 -0
  37. data/app/models/concerns/geo_concerns/basic_geo_metadata.rb +21 -0
  38. data/app/models/concerns/geo_concerns/external_metadata_file_behavior.rb +31 -0
  39. data/app/models/concerns/geo_concerns/extractors/fgdc_helper.rb +9 -0
  40. data/app/models/concerns/geo_concerns/extractors/fgdc_metadata_extractor.rb +114 -0
  41. data/app/models/concerns/geo_concerns/extractors/iso19139_helper.rb +50 -0
  42. data/app/models/concerns/geo_concerns/extractors/mods_helper.rb +15 -0
  43. data/app/models/concerns/geo_concerns/file_set/derivatives.rb +60 -0
  44. data/app/models/concerns/geo_concerns/file_set_presenter_behavior.rb +7 -0
  45. data/app/models/concerns/geo_concerns/geo_file_format_behavior.rb +37 -0
  46. data/app/models/concerns/geo_concerns/geo_file_set_behavior.rb +11 -0
  47. data/app/models/concerns/geo_concerns/georeferenced_behavior.rb +18 -0
  48. data/app/models/concerns/geo_concerns/image_file_behavior.rb +14 -0
  49. data/app/models/concerns/geo_concerns/image_work_behavior.rb +69 -0
  50. data/app/models/concerns/geo_concerns/metadata_extraction_helper.rb +28 -0
  51. data/app/models/concerns/geo_concerns/raster_file_behavior.rb +14 -0
  52. data/app/models/concerns/geo_concerns/raster_work_behavior.rb +82 -0
  53. data/app/models/concerns/geo_concerns/solr_document_behavior.rb +25 -0
  54. data/app/models/concerns/geo_concerns/vector_file_behavior.rb +14 -0
  55. data/app/models/concerns/geo_concerns/vector_work_behavior.rb +78 -0
  56. data/app/presenters/geo_concerns/geo_concerns_show_presenter.rb +30 -0
  57. data/app/presenters/geo_concerns/image_work_show_presenter.rb +18 -0
  58. data/app/presenters/geo_concerns/raster_work_show_presenter.rb +18 -0
  59. data/app/presenters/geo_concerns/vector_work_show_presenter.rb +10 -0
  60. data/app/processors/geo_concerns/processors/base_geo_processor.rb +86 -0
  61. data/app/processors/geo_concerns/processors/raster.rb +11 -0
  62. data/app/processors/geo_concerns/processors/raster/aig.rb +44 -0
  63. data/app/processors/geo_concerns/processors/raster/base.rb +74 -0
  64. data/app/processors/geo_concerns/processors/raster/dem.rb +46 -0
  65. data/app/processors/geo_concerns/processors/raster/processor.rb +27 -0
  66. data/app/processors/geo_concerns/processors/vector.rb +11 -0
  67. data/app/processors/geo_concerns/processors/vector/base.rb +68 -0
  68. data/app/processors/geo_concerns/processors/vector/processor.rb +25 -0
  69. data/app/processors/geo_concerns/processors/vector/shapefile.rb +20 -0
  70. data/app/processors/geo_concerns/processors/zip.rb +31 -0
  71. data/app/renderers/coverage_renderer.rb +34 -0
  72. data/app/runners/geo_concerns/runners/raster_derivatives.rb +9 -0
  73. data/app/runners/geo_concerns/runners/vector_derivatives.rb +9 -0
  74. data/app/schemas/geo_concerns/basic_geo_metadata_optional.rb +39 -0
  75. data/app/schemas/geo_concerns/basic_geo_metadata_required.rb +25 -0
  76. data/app/services/authority_service.rb +23 -0
  77. data/app/services/geo_concerns/derivative_path.rb +16 -0
  78. data/app/services/image_format_service.rb +4 -0
  79. data/app/services/metadata_format_service.rb +4 -0
  80. data/app/services/raster_format_service.rb +4 -0
  81. data/app/services/vector_format_service.rb +4 -0
  82. data/app/values/geo_concerns/coverage.rb +36 -0
  83. data/app/values/geo_concerns/time_period.rb +31 -0
  84. data/app/views/curation_concerns/file_sets/_form.html.erb +48 -0
  85. data/app/views/curation_concerns/image_works/_form.html.erb +23 -0
  86. data/app/views/curation_concerns/image_works/_image_work.html.erb +2 -0
  87. data/app/views/curation_concerns/image_works/_members.html.erb +30 -0
  88. data/app/views/curation_concerns/image_works/_related_image_files.html.erb +24 -0
  89. data/app/views/curation_concerns/image_works/_show_actions.html.erb +16 -0
  90. data/app/views/curation_concerns/image_works/show.html.erb +17 -0
  91. data/app/views/curation_concerns/raster_works/_form.html.erb +25 -0
  92. data/app/views/curation_concerns/raster_works/_members.html.erb +30 -0
  93. data/app/views/curation_concerns/raster_works/_raster_work.html.erb +2 -0
  94. data/app/views/curation_concerns/raster_works/_related_raster_files.html.erb +24 -0
  95. data/app/views/curation_concerns/raster_works/_show_actions.html.erb +16 -0
  96. data/app/views/curation_concerns/raster_works/show.html.erb +17 -0
  97. data/app/views/curation_concerns/vector_works/_form.html.erb +25 -0
  98. data/app/views/curation_concerns/vector_works/_related_vector_files.html.erb +24 -0
  99. data/app/views/curation_concerns/vector_works/_show_actions.html.erb +15 -0
  100. data/app/views/curation_concerns/vector_works/_vector_work.html.erb +2 -0
  101. data/app/views/curation_concerns/vector_works/show.html.erb +15 -0
  102. data/app/views/geo_concerns/_attribute_rows.html.erb +11 -0
  103. data/app/views/geo_concerns/_attributes.html.erb +13 -0
  104. data/app/views/geo_concerns/_form_additional_information.html.erb +11 -0
  105. data/app/views/geo_concerns/_form_bounding_box.html.erb +9 -0
  106. data/app/views/geo_concerns/_form_descriptive_fields.html.erb +9 -0
  107. data/app/views/geo_concerns/_form_files_and_links.html.erb +0 -0
  108. data/app/views/geo_concerns/_form_populate_metadata.html.erb +8 -0
  109. data/app/views/geo_concerns/_form_required_information.html.erb +12 -0
  110. data/app/views/geo_concerns/_form_supplementary_fields.html.erb +15 -0
  111. data/app/views/geo_concerns/_related_external_metadata_files.html.erb +24 -0
  112. data/app/vocabs/geo_concerns/geo_terms.rb +12 -0
  113. data/bin/rails +12 -0
  114. data/config/routes.rb +6 -0
  115. data/geo_concerns.gemspec +36 -0
  116. data/lib/generators/geo_concerns/install_generator.rb +119 -0
  117. data/lib/generators/geo_concerns/templates/actors/curation_concerns/image_work_actor.rb +4 -0
  118. data/lib/generators/geo_concerns/templates/actors/curation_concerns/raster_work_actor.rb +4 -0
  119. data/lib/generators/geo_concerns/templates/actors/curation_concerns/vector_work_actor.rb +4 -0
  120. data/lib/generators/geo_concerns/templates/config/authorities/image_formats.yml +5 -0
  121. data/lib/generators/geo_concerns/templates/config/authorities/metadata_formats.yml +7 -0
  122. data/lib/generators/geo_concerns/templates/config/authorities/raster_formats.yml +9 -0
  123. data/lib/generators/geo_concerns/templates/config/authorities/vector_formats.yml +5 -0
  124. data/lib/generators/geo_concerns/templates/controllers/curation_concerns/file_sets_controller.rb +6 -0
  125. data/lib/generators/geo_concerns/templates/controllers/curation_concerns/image_works_controller.rb +5 -0
  126. data/lib/generators/geo_concerns/templates/controllers/curation_concerns/raster_works_controller.rb +6 -0
  127. data/lib/generators/geo_concerns/templates/controllers/curation_concerns/vector_works_controller.rb +6 -0
  128. data/lib/generators/geo_concerns/templates/geo_concerns.js +1 -0
  129. data/lib/generators/geo_concerns/templates/geo_concerns.scss +3 -0
  130. data/lib/generators/geo_concerns/templates/jobs/characterize_job.rb +12 -0
  131. data/lib/generators/geo_concerns/templates/models/file_set.rb +4 -0
  132. data/lib/generators/geo_concerns/templates/models/image_work.rb +6 -0
  133. data/lib/generators/geo_concerns/templates/models/raster_work.rb +7 -0
  134. data/lib/generators/geo_concerns/templates/models/vector_work.rb +7 -0
  135. data/lib/generators/geo_concerns/templates/presenters/file_set_presenter.rb +3 -0
  136. data/lib/generators/geo_concerns/templates/spec/actor_spec.rb.erb +9 -0
  137. data/lib/generators/geo_concerns/templates/spec/controller_spec.rb.erb +9 -0
  138. data/lib/generators/geo_concerns/templates/spec/model_spec.rb.erb +9 -0
  139. data/lib/geo_concerns.rb +6 -0
  140. data/lib/geo_concerns/engine.rb +4 -0
  141. data/lib/geo_concerns/version.rb +3 -0
  142. data/lib/tasks/geo_concerns_tasks.rake +4 -0
  143. data/solr/config/_rest_managed.json +3 -0
  144. data/solr/config/admin-extra.html +31 -0
  145. data/solr/config/elevate.xml +36 -0
  146. data/solr/config/mapping-ISOLatin1Accent.txt +246 -0
  147. data/solr/config/protwords.txt +21 -0
  148. data/solr/config/schema.xml +372 -0
  149. data/solr/config/scripts.conf +24 -0
  150. data/solr/config/solrconfig.xml +312 -0
  151. data/solr/config/spellings.txt +2 -0
  152. data/solr/config/stopwords.txt +58 -0
  153. data/solr/config/stopwords_en.txt +58 -0
  154. data/solr/config/synonyms.txt +31 -0
  155. data/solr/config/xslt/example.xsl +132 -0
  156. data/solr/config/xslt/example_atom.xsl +67 -0
  157. data/solr/config/xslt/example_rss.xsl +66 -0
  158. data/solr/config/xslt/luke.xsl +337 -0
  159. data/spec/actors/geo_concerns/file_actor_spec.rb +26 -0
  160. data/spec/controllers/image_works_controller_spec.rb +25 -0
  161. data/spec/controllers/raster_works_controller_spec.rb +50 -0
  162. data/spec/controllers/vector_works_controller_spec.rb +50 -0
  163. data/spec/factories/external_metadata_files.rb +20 -0
  164. data/spec/factories/image_files.rb +32 -0
  165. data/spec/factories/image_works.rb +68 -0
  166. data/spec/factories/raster_files.rb +35 -0
  167. data/spec/factories/raster_works.rb +86 -0
  168. data/spec/factories/users.rb +26 -0
  169. data/spec/factories/vector_files.rb +31 -0
  170. data/spec/factories/vector_works.rb +83 -0
  171. data/spec/features/create_raster_work_spec.rb +49 -0
  172. data/spec/forms/geo_concerns/basic_geo_metadata_form_spec.rb +27 -0
  173. data/spec/forms/geo_concerns/external_metadata_file_form_spec.rb +27 -0
  174. data/spec/forms/geo_concerns/georeferenced_form_spec.rb +29 -0
  175. data/spec/forms/geo_concerns/image_work_form_spec.rb +11 -0
  176. data/spec/forms/geo_concerns/raster_work_form_spec.rb +15 -0
  177. data/spec/forms/geo_concerns/vector_work_form_spec.rb +15 -0
  178. data/spec/helpers/bounding_box_helper_spec.rb +34 -0
  179. data/spec/models/concerns/basic_geo_metadata_spec.rb +21 -0
  180. data/spec/models/concerns/geo_concerns/file_set/derivatives_spec.rb +108 -0
  181. data/spec/models/concerns/geo_concerns/file_set/geo_file_format_behavior_spec.rb +56 -0
  182. data/spec/models/external_metadata_file_spec.rb +118 -0
  183. data/spec/models/file_set_spec.rb +9 -0
  184. data/spec/models/image_file_spec.rb +48 -0
  185. data/spec/models/image_work_spec.rb +71 -0
  186. data/spec/models/raster_file_spec.rb +48 -0
  187. data/spec/models/raster_work_spec.rb +122 -0
  188. data/spec/models/solr_document_spec.rb +35 -0
  189. data/spec/models/vector_file_spec.rb +48 -0
  190. data/spec/models/vector_work_spec.rb +113 -0
  191. data/spec/presenters/file_set_presenter_spec.rb +13 -0
  192. data/spec/presenters/geo_concerns_show_presenter_spec.rb +56 -0
  193. data/spec/presenters/image_work_show_presenter_spec.rb +52 -0
  194. data/spec/presenters/raster_work_show_presenter_spec.rb +52 -0
  195. data/spec/presenters/vector_work_show_presenter_spec.rb +41 -0
  196. data/spec/processors/geo_concerns/processors/base_geo_processor_spec.rb +109 -0
  197. data/spec/processors/geo_concerns/processors/raster/aig_spec.rb +28 -0
  198. data/spec/processors/geo_concerns/processors/raster/base_spec.rb +86 -0
  199. data/spec/processors/geo_concerns/processors/raster/dem_spec.rb +26 -0
  200. data/spec/processors/geo_concerns/processors/raster/processor_spec.rb +39 -0
  201. data/spec/processors/geo_concerns/processors/vector/base_spec.rb +67 -0
  202. data/spec/processors/geo_concerns/processors/vector/processor_spec.rb +28 -0
  203. data/spec/processors/geo_concerns/processors/vector/shapefile_spec.rb +17 -0
  204. data/spec/processors/geo_concerns/processors/zip_spec.rb +39 -0
  205. data/spec/renderers/coverage_renderer_spec.rb +21 -0
  206. data/spec/services/derivative_path_spec.rb +12 -0
  207. data/spec/services/raster_format_service_spec.rb +13 -0
  208. data/spec/spec_helper.rb +34 -0
  209. data/spec/support/controllers/engine_helpers.rb +7 -0
  210. data/spec/support/database_cleaner.rb +18 -0
  211. data/spec/support/devise.rb +10 -0
  212. data/spec/support/devise_helpers.rb +6 -0
  213. data/spec/support/factory_girl.rb +3 -0
  214. data/spec/support/features.rb +14 -0
  215. data/spec/support/features/session_helpers.rb +40 -0
  216. data/spec/support/fixture_reader.rb +7 -0
  217. data/spec/test_app_templates/lib/generators/test_app_generator.rb +20 -0
  218. data/spec/values/coverage_spec.rb +40 -0
  219. data/tasks/ci.rake +49 -0
  220. metadata +527 -0
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe GeoConcerns::Processors::Raster::Aig do
4
+ let(:output_file) { 'output/geo.png' }
5
+ let(:file_name) { 'files/aig.zip' }
6
+ let(:options) { { output_format: 'PNG',
7
+ output_size: '150 150',
8
+ min_max: '2.054 11.717',
9
+ label: :thumbnail }
10
+ }
11
+
12
+ subject { described_class.new(file_name, {}) }
13
+
14
+ describe '#translate' do
15
+ it 'returns a gdal_translate command with scaling' do
16
+ expect(subject.class.translate(file_name, options, output_file))
17
+ .to include('-scale 2.054 11.717 255 0')
18
+ end
19
+ end
20
+
21
+ describe '#encode' do
22
+ it 'wraps encode_raster in an unzip block' do
23
+ allow(subject.class).to receive(:unzip).and_yield(file_name)
24
+ expect(subject.class).to receive(:encode_raster)
25
+ subject.class.encode(file_name, options, output_file)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ describe GeoConcerns::Processors::Raster::Base do
4
+ let(:output_file) { 'output/geo.png' }
5
+ let(:file_name) { 'files/geo.tif' }
6
+ let(:label) {}
7
+ let(:options) { { output_format: 'PNG', output_size: '150 150', label: label } }
8
+
9
+ subject { described_class.new(file_name, {}) }
10
+
11
+ describe '#encode' do
12
+ context 'when output label is thumbnail' do
13
+ let(:label) { :thumbnail }
14
+ it 'calls the encode_raster method' do
15
+ expect(subject.class).to receive(:encode_raster)
16
+ subject.class.encode(file_name, options, output_file)
17
+ end
18
+ end
19
+
20
+ context 'when output label is display_raster' do
21
+ let(:label) { :display_raster }
22
+ it 'calls the reproject_raster method' do
23
+ expect(subject.class).to receive(:reproject_raster)
24
+ subject.class.encode(file_name, options, output_file)
25
+ end
26
+ end
27
+ end
28
+
29
+ describe '#encode_raster' do
30
+ it 'executes the translate command and cleans up aux file' do
31
+ expect(subject.class).to receive(:execute)
32
+ expect(File).to receive(:unlink).with("#{output_file}.aux.xml")
33
+ subject.class.encode_raster(file_name, options, output_file)
34
+ end
35
+ end
36
+
37
+ describe '#reproject_raster' do
38
+ it 'executes the warp and compress commands, then cleans up intermediate file' do
39
+ expect(subject.class).to receive(:execute).twice
40
+ expect(FileUtils).to receive(:rm_rf)
41
+ subject.class.reproject_raster(file_name, options, output_file)
42
+ end
43
+ end
44
+
45
+ describe '#warp' do
46
+ it 'returns a gdalwarp command ' do
47
+ expect(subject.class.warp(file_name, options, output_file))
48
+ .to include('gdalwarp')
49
+ end
50
+ end
51
+
52
+ describe '#compress' do
53
+ it 'returns a gdal_translate command with a compress option' do
54
+ expect(subject.class.compress(file_name, options, output_file))
55
+ .to include('gdal_translate', 'COMPRESS=LZW')
56
+ end
57
+ end
58
+
59
+ describe '#get_raster_min_max' do
60
+ let(:min_max) { subject.class.get_raster_min_max(info_string) }
61
+
62
+ context 'when a string has computed min and max' do
63
+ let(:info_string) { 'Band 1 Block=256x16 Type=Float32 Computed Min/Max=2.054,11.717 ' }
64
+
65
+ it 'returns with formatted text' do
66
+ expect(min_max).to eq('2.054 11.717')
67
+ end
68
+ end
69
+
70
+ context 'when a string does not have a computed min and max' do
71
+ let(:info_string) { 'Band 1 Block=256x16 Type=Float32' }
72
+
73
+ it 'returns with formatted text' do
74
+ expect(min_max).to eq('')
75
+ end
76
+ end
77
+ end
78
+
79
+ describe '#gdalinfo' do
80
+ it 'shells out to gdalinfo and returns the output as a string' do
81
+ expect(Open3).to receive(:capture3).with("gdalinfo -mm #{file_name}")
82
+ .and_return(['info', '', ''])
83
+ expect(subject.class.gdalinfo(file_name)).to eq('info')
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe GeoConcerns::Processors::Raster::Dem do
4
+ let(:output_file) { 'output/geo.png' }
5
+ let(:file_name) { 'files/geo.dem' }
6
+ let(:options) { { output_format: 'PNG',
7
+ output_size: '150 150',
8
+ label: :thumbnail }
9
+ }
10
+
11
+ subject { described_class.new(file_name, {}) }
12
+
13
+ describe '#translate' do
14
+ it 'returns a translate command for the USGS Digital Elevation Model format' do
15
+ expect(subject.class.translate(file_name, options, output_file))
16
+ .to include('USGSDEM')
17
+ end
18
+ end
19
+
20
+ describe '#hillshade' do
21
+ it 'returns a gdal hillshade command' do
22
+ expect(subject.class.hillshade(file_name, options, output_file))
23
+ .to include('gdaldem hillshade')
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe GeoConcerns::Processors::Raster::Processor do
4
+ subject { described_class.new(file_name, directives) }
5
+ let(:processor) { double }
6
+
7
+ context 'when a usgs ascii dem format type is passed' do
8
+ let(:file_name) { 'files/geo.dem' }
9
+ let(:directives) { { input_format: 'text/plain; gdal-format=USGSDEM' } }
10
+
11
+ it 'calls the DEM processor' do
12
+ expect(GeoConcerns::Processors::Raster::Dem).to receive(:new).and_return(processor)
13
+ expect(processor).to receive(:process)
14
+ subject.process
15
+ end
16
+ end
17
+
18
+ context 'when an Arc/Info Binary Grid format type is passed' do
19
+ let(:file_name) { 'files/aig.zip' }
20
+ let(:directives) { { input_format: 'application/octet-stream; gdal-format=AIG' } }
21
+
22
+ it 'calls the AIG processor' do
23
+ expect(GeoConcerns::Processors::Raster::Aig).to receive(:new).and_return(processor)
24
+ expect(processor).to receive(:process)
25
+ subject.process
26
+ end
27
+ end
28
+
29
+ context 'when a GeoTIFF format type is passed' do
30
+ let(:file_name) { 'files/geo.tif' }
31
+ let(:directives) { { input_format: 'image/tiff; gdal-format=GTiff' } }
32
+
33
+ it 'calls the base raster processor' do
34
+ expect(GeoConcerns::Processors::Raster::Base).to receive(:new).and_return(processor)
35
+ expect(processor).to receive(:process)
36
+ subject.process
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe GeoConcerns::Processors::Vector::Base do
4
+ let(:output_file) { 'output/geo.png' }
5
+ let(:file_name) { 'files/geo.zip' }
6
+ let(:label) {}
7
+ let(:options) { { output_format: 'PNG', output_size: '150 150', label: label } }
8
+
9
+ subject { described_class.new(file_name, {}) }
10
+
11
+ describe '#encode' do
12
+ context 'when output label is thumbnail' do
13
+ let(:label) { :thumbnail }
14
+ it 'calls the encode_vector method' do
15
+ expect(subject.class).to receive(:encode_vector)
16
+ subject.class.encode(file_name, options, output_file)
17
+ end
18
+ end
19
+
20
+ context 'when output label is display_vector' do
21
+ let(:label) { :display_vector }
22
+ it 'calls the reproject_vector method' do
23
+ expect(subject.class).to receive(:reproject_vector)
24
+ subject.class.encode(file_name, options, output_file)
25
+ end
26
+ end
27
+ end
28
+
29
+ describe '#encode_vector' do
30
+ it 'executes rasterize and translate commands, and cleans up files' do
31
+ expect(subject.class).to receive(:execute).twice
32
+ expect(File).to receive(:unlink)
33
+ expect(File).to receive(:unlink).with("#{output_file}.aux.xml")
34
+ subject.class.encode_vector(file_name, options, output_file)
35
+ end
36
+ end
37
+
38
+ describe '#reproject_vector' do
39
+ it 'executes the reproject command, zips the output, then cleans up' do
40
+ expect(subject.class).to receive(:execute)
41
+ expect(subject.class).to receive(:zip)
42
+ expect(FileUtils).to receive(:rm_rf)
43
+ subject.class.reproject_vector(file_name, options, output_file)
44
+ end
45
+ end
46
+
47
+ describe '#rasterize' do
48
+ it 'returns a gdal_rasterize command ' do
49
+ expect(subject.class.rasterize(file_name, options, output_file))
50
+ .to include('gdal_rasterize')
51
+ end
52
+ end
53
+
54
+ describe '#reproject' do
55
+ it 'returns a ogr2ogr command' do
56
+ expect(subject.class.reproject(file_name, options, output_file))
57
+ .to include('ogr2ogr', 'ESRI Shapefile')
58
+ end
59
+ end
60
+
61
+ describe '#intermediate_shapefile_path' do
62
+ it 'returns a path to a shapefile' do
63
+ expect(subject.class.intermediate_shapefile_path('/test/path/file.zip'))
64
+ .to eq('/test/path/file/')
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe GeoConcerns::Processors::Vector::Processor do
4
+ subject { described_class.new(file_name, directives) }
5
+ let(:processor) { double }
6
+
7
+ context 'when a shapefile format type is passed' do
8
+ let(:file_name) { 'files/shapefile.zip' }
9
+ let(:directives) { { input_format: 'application/zip; ogr-format="ESRI Shapefile"' } }
10
+
11
+ it 'calls the shapefile processor' do
12
+ expect(GeoConcerns::Processors::Vector::Shapefile).to receive(:new).and_return(processor)
13
+ expect(processor).to receive(:process)
14
+ subject.process
15
+ end
16
+ end
17
+
18
+ context 'when a geojson format type is passed' do
19
+ let(:file_name) { 'files/geo.json' }
20
+ let(:directives) { { input_format: 'application/vnd.geo+json' } }
21
+
22
+ it 'calls the base vector processor' do
23
+ expect(GeoConcerns::Processors::Vector::Base).to receive(:new).and_return(processor)
24
+ expect(processor).to receive(:process)
25
+ subject.process
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe GeoConcerns::Processors::Vector::Shapefile do
4
+ let(:output_file) { 'output/geo.png' }
5
+ let(:file_name) { 'files/Shapefile.zip' }
6
+ let(:options) { { output_format: 'PNG', output_size: '150 150', label: :thumbnail } }
7
+
8
+ subject { described_class.new(file_name, {}) }
9
+
10
+ describe '#encode' do
11
+ it 'wraps encode vector method in an unzip block' do
12
+ allow(subject.class).to receive(:unzip).and_yield(file_name)
13
+ expect(subject.class).to receive(:encode_vector)
14
+ subject.class.encode(file_name, options, output_file)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe GeoConcerns::Processors::Zip do
4
+ before do
5
+ class TestProcessor
6
+ include Hydra::Derivatives::Processors::ShellBasedProcessor
7
+ include GeoConcerns::Processors::Zip
8
+ end
9
+ end
10
+
11
+ after { Object.send(:remove_const, :TestProcessor) }
12
+
13
+ subject { TestProcessor.new }
14
+ let(:path) { 'files/test.zip' }
15
+ let(:output_file) { 'output/test.tif' }
16
+
17
+ describe '#unzip' do
18
+ let(:command) { 'unzip -qq -j -d "output/test_out" "files/test.zip"' }
19
+
20
+ context 'given an input and output path' do
21
+ it 'runs an unzip command and yields to a block' do
22
+ arg = ''
23
+ expect(subject.class).to receive(:execute).with(command)
24
+ expect(FileUtils).to receive(:rm_rf)
25
+ subject.class.unzip(path, output_file) { |a| arg = a }
26
+ expect(arg).to eq('output/test_out')
27
+ end
28
+ end
29
+ end
30
+
31
+ describe '#zip' do
32
+ let(:command) { 'zip -j -qq -r "output/test.tif" "files/test.zip"' }
33
+
34
+ it 'runs a zip command ' do
35
+ expect(subject.class).to receive(:execute).with(command)
36
+ subject.class.zip(path, output_file)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe CoverageRenderer do
4
+ let(:coverage) { 'northlimit=2.7; eastlimit=4.0; southlimit=1.3; westlimit=2.9; units=degrees; projection=EPSG:4326' }
5
+ let(:renderer) { described_class.new(:coverage, [coverage]) }
6
+ subject { renderer.render }
7
+
8
+ it 'includes the coverage string' do
9
+ expect(subject).to include coverage
10
+ end
11
+
12
+ it 'includes a map' do
13
+ expect(subject).to include "<div id='bbox'"
14
+ expect(subject).to include "<script>boundingBoxSelector"
15
+ end
16
+
17
+ it 'includes a toggle button' do
18
+ expect(subject).to include "<a data-toggle='collapse' data-parent='accordion' href='#bbox'"
19
+ expect(subject).to include "Toggle Map"
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe GeoConcerns::DerivativePath do
4
+ describe '#extension_for' do
5
+ it 'returns the appropriate file extension for a geo derivative' do
6
+ expect(described_class.extension_for('thumbnail')).to eq('.jpeg')
7
+ expect(described_class.extension_for('display_raster')).to eq('.tif')
8
+ expect(described_class.extension_for('display_vector')).to eq('.zip')
9
+ expect(described_class.extension_for('simplified')).to eq('.simplified')
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe RasterFormatService do
4
+ subject { described_class }
5
+
6
+ it 'has select_options' do
7
+ expect(subject.select_options).to eq([['GeoTIFF', 'image/tiff; gdal-format=GTiff'], ['Arc/Info ASCII Grid', 'text/plain; gdal-format=AAIGrid'], ['Arc/Info Binary Grid', 'application/octet-stream; gdal-format=AIG'], ['USGS ASCII DEM', 'text/plain; gdal-format=USGSDEM']])
8
+ end
9
+
10
+ it 'looks up a label for a term' do
11
+ expect(subject.label('image/tiff; gdal-format=GTiff')).to eq('GeoTIFF')
12
+ end
13
+ end
@@ -0,0 +1,34 @@
1
+ require 'simplecov'
2
+
3
+ if ENV['CI']
4
+ require 'coveralls'
5
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
6
+ end
7
+
8
+ if ENV['COVERAGE'] || ENV['CI']
9
+ SimpleCov.start('rails') do
10
+ add_filter '/spec'
11
+ add_filter '/.internal_test_app'
12
+ add_filter '/lib/generators'
13
+ add_filter '/lib/geo_concerns/version.rb'
14
+ end
15
+ end
16
+
17
+ require 'engine_cart'
18
+ require 'pry'
19
+
20
+ ENV['RAILS_ENV'] ||= 'test'
21
+ EngineCart.load_application!
22
+ Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
23
+ require 'rspec/rails'
24
+
25
+ RSpec.configure do |config|
26
+ config.expect_with :rspec do |expectations|
27
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
28
+ end
29
+
30
+ config.mock_with :rspec do |mocks|
31
+ mocks.verify_partial_doubles = true
32
+ end
33
+ config.fixture_path = File.expand_path("../fixtures", __FILE__)
34
+ end
@@ -0,0 +1,7 @@
1
+ module Controllers
2
+ module EngineHelpers
3
+ def main_app
4
+ Rails.application.class.routes.url_helpers
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ require 'database_cleaner'
2
+ require 'active_fedora/cleaner'
3
+ RSpec.configure do |config|
4
+ config.before :each do
5
+ DatabaseCleaner.strategy = :transaction
6
+ DatabaseCleaner.start
7
+ end
8
+
9
+ config.after do
10
+ DatabaseCleaner.clean
11
+ end
12
+
13
+ config.before :each do |example|
14
+ unless example.metadata[:type] == :view || example.metadata[:no_clean]
15
+ ActiveFedora::Cleaner.clean!
16
+ end
17
+ end
18
+ end