geo_concerns 0.0.10 → 0.1.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.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/.travis.yml +8 -4
  4. data/README.md +23 -8
  5. data/app/controllers/concerns/geo_concerns/messenger_behavior.rb +29 -0
  6. data/app/jobs/delivery_job.rb +15 -2
  7. data/app/jobs/geoblacklight_job.rb +10 -0
  8. data/app/models/concerns/geo_concerns/file_set/derivatives.rb +11 -9
  9. data/app/models/concerns/geo_concerns/solr_document_behavior.rb +5 -0
  10. data/app/presenters/geo_concerns/geo_concerns_show_presenter.rb +1 -1
  11. data/app/processors/geo_concerns/processors/base_geo_processor.rb +9 -24
  12. data/app/processors/geo_concerns/processors/image.rb +59 -0
  13. data/app/processors/geo_concerns/processors/ogr.rb +1 -1
  14. data/app/processors/geo_concerns/processors/raster.rb +18 -3
  15. data/app/processors/geo_concerns/processors/raster/base.rb +1 -0
  16. data/app/processors/geo_concerns/processors/rendering.rb +79 -0
  17. data/app/processors/geo_concerns/processors/vector.rb +16 -3
  18. data/app/processors/geo_concerns/processors/vector/base.rb +3 -2
  19. data/app/processors/geo_concerns/processors/vector/info.rb +21 -3
  20. data/app/services/geo_concerns/delivery/geoserver.rb +43 -6
  21. data/app/services/geo_concerns/discovery/abstract_document.rb +2 -1
  22. data/app/services/geo_concerns/discovery/document_builder.rb +2 -3
  23. data/app/services/geo_concerns/discovery/document_builder/basic_metadata_builder.rb +13 -2
  24. data/app/services/geo_concerns/discovery/document_builder/date_builder.rb +2 -0
  25. data/app/services/geo_concerns/discovery/document_builder/document_path.rb +12 -7
  26. data/app/services/geo_concerns/discovery/document_builder/references_builder.rb +20 -1
  27. data/app/services/geo_concerns/discovery/document_builder/spatial_builder.rb +2 -0
  28. data/app/services/geo_concerns/discovery/document_builder/wxs.rb +81 -0
  29. data/app/services/geo_concerns/discovery/geoblacklight_document.rb +9 -3
  30. data/app/services/geo_concerns/events_generator.rb +25 -0
  31. data/app/services/geo_concerns/events_generator/base_events_generator.rb +22 -0
  32. data/app/services/geo_concerns/events_generator/composite_generator.rb +18 -0
  33. data/app/services/geo_concerns/events_generator/geoblacklight_event_generator.rb +44 -0
  34. data/app/services/geo_concerns/events_generator/geoserver_event_generator.rb +30 -0
  35. data/app/services/geo_concerns/local_messaging_client.rb +18 -0
  36. data/app/services/geo_concerns/rabbit_messaging_client.rb +38 -0
  37. data/app/values/geo_concerns/time_period.rb +4 -5
  38. data/app/views/geo_concerns/_attribute_rows.html.erb +1 -0
  39. data/app/views/geo_concerns/_form_additional_information.html.erb +1 -0
  40. data/app/views/geo_concerns/file_sets/actions/_default_actions.html.erb +1 -1
  41. data/app/views/geo_concerns/file_sets/actions/_image_actions.html.erb +1 -1
  42. data/app/views/geo_concerns/file_sets/actions/_metadata_actions.html.erb +1 -1
  43. data/app/views/geo_concerns/file_sets/actions/_raster_actions.html.erb +2 -2
  44. data/app/views/geo_concerns/file_sets/actions/_vector_actions.html.erb +2 -2
  45. data/app/views/geo_concerns/file_sets/media_display/_geo.html.erb +2 -1
  46. data/docker-compose-full.yml +30 -0
  47. data/docker-compose.yml +4 -5
  48. data/geo_concerns.gemspec +5 -4
  49. data/lib/generators/geo_concerns/install_generator.rb +19 -25
  50. data/lib/generators/geo_concerns/templates/config/geoblacklight.yml +12 -0
  51. data/lib/generators/geo_concerns/templates/config/geoserver.yml +2 -0
  52. data/lib/generators/geo_concerns/templates/config/initializers/geoblacklight_config.rb +13 -0
  53. data/lib/generators/geo_concerns/templates/config/initializers/messaging_config.rb +34 -0
  54. data/lib/generators/geo_concerns/templates/config/initializers/simpler_tiles.rb +65 -0
  55. data/lib/generators/geo_concerns/templates/config/messaging.yml +15 -0
  56. data/lib/generators/geo_concerns/templates/config/simpler_tiles.yml +24 -0
  57. data/lib/generators/geo_concerns/templates/controllers/curation_concerns/file_sets_controller.rb +1 -0
  58. data/lib/generators/geo_concerns/templates/controllers/curation_concerns/image_works_controller.rb +1 -0
  59. data/lib/generators/geo_concerns/templates/controllers/curation_concerns/raster_works_controller.rb +1 -0
  60. data/lib/generators/geo_concerns/templates/controllers/curation_concerns/vector_works_controller.rb +1 -0
  61. data/lib/geo_concerns/version.rb +1 -1
  62. data/run-docker.sh +11 -1
  63. data/spec/controllers/file_sets_controller_spec.rb +50 -0
  64. data/spec/jobs/delivery_job_spec.rb +30 -7
  65. data/spec/models/concerns/geo_concerns/file_set/derivatives_spec.rb +9 -3
  66. data/spec/models/solr_document_spec.rb +6 -0
  67. data/spec/processors/geo_concerns/processors/base_geo_processor_spec.rb +15 -22
  68. data/spec/processors/geo_concerns/processors/image_spec.rb +71 -0
  69. data/spec/processors/geo_concerns/processors/rendering_spec.rb +64 -0
  70. data/spec/processors/geo_concerns/processors/vector/base_spec.rb +1 -1
  71. data/spec/processors/geo_concerns/processors/vector/info_spec.rb +10 -1
  72. data/spec/services/geo_concerns/delivery/geoserver_spec.rb +30 -6
  73. data/spec/services/{derivative_path_spec.rb → geo_concerns/derivative_path_spec.rb} +0 -0
  74. data/spec/services/geo_concerns/discovery/document_builder/wxs_spec.rb +69 -0
  75. data/spec/services/geo_concerns/discovery/document_builder_spec.rb +48 -32
  76. data/spec/services/geo_concerns/discovery/geoblacklight_document_spec.rb +1 -0
  77. data/spec/services/geo_concerns/events_generator/geoblacklight_event_generator_spec.rb +87 -0
  78. data/spec/services/geo_concerns/events_generator/geoserver_event_generator_spec.rb +40 -0
  79. data/spec/services/geo_concerns/local_messaging_client_spec.rb +35 -0
  80. data/spec/services/geo_concerns/rabbit_messaging_client_spec.rb +35 -0
  81. data/spec/services/{raster_format_service_spec.rb → geo_concerns/raster_format_service_spec.rb} +0 -0
  82. data/template.rb +1 -1
  83. metadata +85 -31
  84. data/app/processors/geo_concerns/processors/mapnik.rb +0 -35
  85. data/app/processors/geo_concerns/processors/raster/processor.rb +0 -26
  86. data/app/processors/geo_concerns/processors/vector/processor.rb +0 -24
  87. data/lib/generators/geo_concerns/templates/config/locales/geo_concerns.en.yml +0 -4
  88. data/lib/generators/geo_concerns/templates/config/mapnik.yml +0 -24
  89. data/spec/processors/geo_concerns/processors/mapnik_spec.rb +0 -70
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7a2c566517e2692c326da44ff6ac325a8605e91
4
- data.tar.gz: 19af506201f28b351939901a46fb02dd599c6ff7
3
+ metadata.gz: d62f2f9412e6303a2245195a93b9d18b15c19461
4
+ data.tar.gz: 0e2cb97544d7aa1ace8c595f89637833bb00d860
5
5
  SHA512:
6
- metadata.gz: 07c9520851640a1241417a758dea76fc4bc284e1463ee62d39b14de0b6bc675bf1e8063843b31d8a4d9ef664d094eb903a3758fc5b02ac68e744847586382cf5
7
- data.tar.gz: 6d097f13341e4f4d5350bf89f6dba9f9eaff1a6808c5229b1a4993e4c6cea48244368e3d82fc6bf39211e2c0b382a5daa5f928d545e14f323ca3cc032e2a451c
6
+ metadata.gz: a0fa7ca52d44573c6bce5021977bc0502c87ebd125cf4f20b1725203ee761494b528ed7a7d196a284d8df1388b7b76af20685a0e6e59b399663bb13132632a27
7
+ data.tar.gz: 94b8701dcd59dcfc1160ddb11e9cbae5a03da1e925305b61eb9c90473904000984012c5d6edb74cebd30cfe1c0f0b2390f84ecbca02c4c0dbad17f44d201cf92
data/.rubocop.yml CHANGED
@@ -49,6 +49,7 @@ Metrics/MethodLength:
49
49
  Exclude:
50
50
  - 'Rakefile'
51
51
  - 'app/models/concerns/geo_concerns/extractors/iso19139_helper.rb'
52
+ - 'app/models/concerns/geo_concerns/file_set/derivatives.rb'
52
53
 
53
54
  Metrics/ClassLength:
54
55
  Exclude:
data/.travis.yml CHANGED
@@ -8,16 +8,17 @@ jdk:
8
8
  env:
9
9
  global:
10
10
  - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
11
- - MAPNIK_VERSION="2.3"
12
11
  matrix:
13
12
  - RAILS_VERSION=4.2.7.1
14
13
  RDF_VERSION=1.99.1
15
14
  - RAILS_VERSION=5.0.0.1
16
15
  RDF_VERSION=2.1.0
17
16
  before_install:
18
- - sudo apt-add-repository --yes ppa:mapnik/nightly-${MAPNIK_VERSION}
19
- - sudo apt-get update -y
20
- - sudo apt-get -y install libmapnik=${MAPNIK_VERSION}* mapnik-utils=${MAPNIK_VERSION}* libmapnik-dev=${MAPNIK_VERSION}* mapnik-input-plugin*=${MAPNIK_VERSION}*
17
+ - git clone https://github.com/propublica/simple-tiles.git
18
+ - cd simple-tiles
19
+ - ./configure && make
20
+ - sudo make install
21
+ - cd ..
21
22
  - gem install bundler -v 1.13.1 # hopefully temporary
22
23
  install: bundle install --jobs=3 --retry=3
23
24
  before_script:
@@ -27,4 +28,7 @@ services:
27
28
  addons:
28
29
  apt:
29
30
  packages:
31
+ - libgdal-dev
30
32
  - gdal-bin
33
+ - libcairo2-dev
34
+ - libpango1.0-dev
data/README.md CHANGED
@@ -23,18 +23,32 @@ Rails application for developing Hydra Geo models. Built around Curation Concern
23
23
  * On Ubuntu, use `sudo apt-get install gdal-bin`.
24
24
  1. [GeoServer](http://geoserver.org/) (Optional)
25
25
 
26
- ## Mapnik
26
+ ## Simple Tiles
27
27
 
28
- GeoConcerns requires that Mapnik 3.x or 2.x be installed at `/usr/local/lib/libmapnik.*`. For linux, a C++ compiler and build environment is also needed.
28
+ GeoConcerns requires the image generation library [Simple Tiles](http://propublica.github.io/simple-tiles/).
29
29
 
30
30
  Mac OS X:
31
31
 
32
- - https://github.com/mapnik/mapnik/wiki/MacInstallation or ```brew install mapnik```
32
+ - Install via Homebrew: ```brew install simple-tiles```
33
33
 
34
34
  Linux:
35
35
 
36
- - https://github.com/mapnik/mapnik/wiki/LinuxInstallation
37
- - Build environment: [gcc](https://help.ubuntu.com/community/InstallingCompilers) or clang
36
+ - Install dependencies:
37
+
38
+ ```
39
+ libgdal-dev
40
+ libcairo2-dev
41
+ libpango1.0-dev
42
+ ```
43
+
44
+ - Compile:
45
+
46
+ ```
47
+ $ git clone git@github.com:propublica/simple-tiles.git
48
+ $ cd simple-tiles
49
+ $ ./configure
50
+ $ make && make install
51
+ ```
38
52
 
39
53
  ## Installation
40
54
 
@@ -49,8 +63,9 @@ $ rake hydra:server
49
63
  Add GeoConcerns models to an existing CurationConcerns application:
50
64
 
51
65
  1. Add `gem 'geo_concerns'` to your Gemfile.
52
- 2. `bundle install`
53
- 3. `rails generate geo_concerns:install`
66
+ 1. `bundle install`
67
+ 1. `rails generate curation_concerns:install`
68
+ 1. `rails generate geo_concerns:install -f`
54
69
 
55
70
  ## Development
56
71
 
@@ -122,4 +137,4 @@ rspec spec/path/to/your_spec.rb:linenumber
122
137
  $ cd geoserver-vagrant/
123
138
  $ vagrant up
124
139
 
125
- ```
140
+ ```
@@ -0,0 +1,29 @@
1
+ module GeoConcerns
2
+ module MessengerBehavior
3
+ extend ActiveSupport::Concern
4
+
5
+ def destroy
6
+ messenger.record_deleted(geo_concern)
7
+ super
8
+ end
9
+
10
+ def after_create_response
11
+ super
12
+ messenger.record_created(geo_concern)
13
+ end
14
+
15
+ def after_update_response
16
+ super
17
+ messenger.record_updated(geo_concern)
18
+ end
19
+
20
+ def messenger
21
+ @messenger ||= Messaging.messenger
22
+ end
23
+
24
+ def geo_concern
25
+ doc = SolrDocument.new(curation_concern.to_solr)
26
+ show_presenter.new(doc, current_ability, request)
27
+ end
28
+ end
29
+ end
@@ -10,9 +10,22 @@ class DeliveryJob < ActiveJob::Base
10
10
  # Precondition is that all derivatives are created and saved.
11
11
  # @param [FileSet] file_set
12
12
  # @param [String] content_url contains the display copy to deliver
13
- def perform(file_set, content_url)
14
- uri = URI.parse(content_url)
13
+ def perform(message)
14
+ file_set = ActiveFedora::Base.find(message['id'])
15
+ uri = URI.parse(content_url(file_set))
16
+ raise NotImplementedError, 'Only supports vector and raster file formats' if uri.path == ''
15
17
  raise NotImplementedError, 'Only supports file URLs' unless uri.scheme == 'file'
16
18
  GeoConcerns::DeliveryService.new(file_set, uri.path).publish
17
19
  end
20
+
21
+ def content_url(file_set)
22
+ case file_set.geo_mime_type
23
+ when *GeoConcerns::RasterFormatService.select_options.map(&:last)
24
+ return file_set.send(:derivative_url, 'display_raster')
25
+ when *GeoConcerns::VectorFormatService.select_options.map(&:last)
26
+ return file_set.send(:derivative_url, 'display_vector')
27
+ else
28
+ return ''
29
+ end
30
+ end
18
31
  end
@@ -0,0 +1,10 @@
1
+ require 'uri'
2
+
3
+ # Loads geoblacklight
4
+ class GeoblacklightJob < ActiveJob::Base
5
+ queue_as :default
6
+
7
+ def perform(message)
8
+ GeoblacklightMessaging::GeoblacklightEventProcessor.new(message).process
9
+ end
10
+ end
@@ -3,31 +3,25 @@ module GeoConcerns
3
3
  module Derivatives
4
4
  extend ActiveSupport::Concern
5
5
 
6
- # rubocop:disable Metrics/MethodLength
7
6
  def create_derivatives(filename)
8
- content_url = nil
9
7
  case geo_mime_type
10
8
  when *GeoConcerns::ImageFormatService.select_options.map(&:last)
11
9
  image_derivatives(filename)
12
10
  when *GeoConcerns::RasterFormatService.select_options.map(&:last)
13
11
  raster_derivatives(filename)
14
- content_url = derivative_url('display_raster')
15
12
  when *GeoConcerns::VectorFormatService.select_options.map(&:last)
16
13
  vector_derivatives(filename)
17
- content_url = derivative_url('display_vector')
18
14
  end
19
-
20
15
  super
21
16
 
22
- # Once all the derivatives are created, we can run a job to
23
- # deliver them to external services
24
- DeliveryJob.perform_later(self, content_url) if content_url.present?
17
+ # Once all the derivatives are created, send a derivatives created message
18
+ messenger.derivatives_created(self)
25
19
  end
26
- # rubocop:enable Metrics/MethodLength
27
20
 
28
21
  def image_derivatives(filename)
29
22
  Hydra::Derivatives::ImageDerivatives
30
23
  .create(filename, outputs: [{ label: :thumbnail,
24
+ id: id,
31
25
  format: 'png',
32
26
  size: '200x150>',
33
27
  url: derivative_url('thumbnail') }])
@@ -37,10 +31,12 @@ module GeoConcerns
37
31
  GeoConcerns::Runners::RasterDerivatives
38
32
  .create(filename, outputs: [{ input_format: geo_mime_type,
39
33
  label: :display_raster,
34
+ id: id,
40
35
  format: 'tif',
41
36
  url: derivative_url('display_raster') },
42
37
  { input_format: geo_mime_type,
43
38
  label: :thumbnail,
39
+ id: id,
44
40
  format: 'png',
45
41
  size: '200x150',
46
42
  url: derivative_url('thumbnail') }])
@@ -50,10 +46,12 @@ module GeoConcerns
50
46
  GeoConcerns::Runners::VectorDerivatives
51
47
  .create(filename, outputs: [{ input_format: geo_mime_type,
52
48
  label: :display_vector,
49
+ id: id,
53
50
  format: 'zip',
54
51
  url: derivative_url('display_vector') },
55
52
  { input_format: geo_mime_type,
56
53
  label: :thumbnail,
54
+ id: id,
57
55
  format: 'png',
58
56
  size: '200x150',
59
57
  url: derivative_url('thumbnail') }])
@@ -64,6 +62,10 @@ module GeoConcerns
64
62
  def derivative_path_factory
65
63
  GeoConcerns::DerivativePath
66
64
  end
65
+
66
+ def messenger
67
+ @messenger ||= Messaging.messenger
68
+ end
67
69
  end
68
70
  end
69
71
  end
@@ -37,5 +37,10 @@ module GeoConcerns
37
37
  dt = first(Solrizer.solr_name('system_modified', :stored_sortable, type: :date))
38
38
  dt.nil? ? nil : DateTime.parse(dt).utc
39
39
  end
40
+
41
+ # @return [Array<String>]
42
+ def identifier
43
+ fetch(Solrizer.solr_name('identifier'), [])
44
+ end
40
45
  end
41
46
  end
@@ -1,7 +1,7 @@
1
1
  module GeoConcerns
2
2
  class GeoConcernsShowPresenter < CurationConcerns::WorkShowPresenter
3
3
  delegate :spatial, :temporal, :issued, :coverage, :provenance, :layer_modified,
4
- to: :solr_document
4
+ :identifier, to: :solr_document
5
5
  class_attribute :file_format_service
6
6
 
7
7
  def geo_file_set_presenters
@@ -1,5 +1,3 @@
1
- require 'mini_magick'
2
-
3
1
  module GeoConcerns
4
2
  module Processors
5
3
  module BaseGeoProcessor
@@ -36,26 +34,6 @@ module GeoConcerns
36
34
  time = (Time.now.to_f * 1000).to_i
37
35
  "#{File.dirname(path)}/#{File.basename(path, File.extname(path))}_#{time}"
38
36
  end
39
-
40
- # Uses imagemagick to resize an image and convert it to the output format.
41
- # Keeps the aspect ratio of the original image and adds padding to
42
- # to the output image. The file extension is the output format.
43
- # @param in_path [String] file input path
44
- # @param out_path [String] processor output file path.
45
- # @param options [Hash] creation options
46
- # @option options [String] `:output_size` as "w h" or "wxh"
47
- def self.convert(in_path, out_path, options)
48
- image = MiniMagick::Image.open(in_path) # copies image
49
- image.combine_options do |i|
50
- size = options[:output_size].tr(' ', 'x')
51
- i.resize size
52
- i.background 'white'
53
- i.gravity 'center'
54
- i.extent size
55
- end
56
- image.format File.extname(out_path).gsub(/^\./, '')
57
- image.write(out_path)
58
- end
59
37
  end
60
38
 
61
39
  def options_for(_format)
@@ -63,7 +41,8 @@ module GeoConcerns
63
41
  label: label,
64
42
  output_size: output_size,
65
43
  output_srid: output_srid,
66
- basename: basename
44
+ basename: basename,
45
+ id: id
67
46
  }
68
47
  end
69
48
 
@@ -73,7 +52,7 @@ module GeoConcerns
73
52
  directives.fetch(:label, '')
74
53
  end
75
54
 
76
- # Tranforms the size directive into a GDAL size parameter.
55
+ # Transforms the size directive into a GDAL size parameter.
77
56
  # @return [String] derivative size
78
57
  def output_size
79
58
  return unless directives[:size]
@@ -91,6 +70,12 @@ module GeoConcerns
91
70
  def basename
92
71
  File.basename(source_path, File.extname(source_path))
93
72
  end
73
+
74
+ # Gets the fileset id or returns nil.
75
+ # @return [String] fileset id
76
+ def id
77
+ directives.fetch(:id, nil)
78
+ end
94
79
  end
95
80
  end
96
81
  end
@@ -0,0 +1,59 @@
1
+ require 'mini_magick'
2
+
3
+ module GeoConcerns
4
+ module Processors
5
+ module Image
6
+ extend ActiveSupport::Concern
7
+ included do
8
+ # Uses imagemagick to resize an image and convert it to the output format.
9
+ # Keeps the aspect ratio of the original image and adds padding to
10
+ # to the output image. The file extension is the output format.
11
+ # @param in_path [String] file input path
12
+ # @param out_path [String] processor output file path.
13
+ # @param options [Hash] creation options
14
+ # @option options [String] `:output_size` as "w h" or "wxh"
15
+ def self.convert(in_path, out_path, options)
16
+ image = MiniMagick::Image.open(in_path) # copies image
17
+ image.combine_options do |i|
18
+ size = options[:output_size].tr(' ', 'x')
19
+ i.resize size
20
+ i.background 'white'
21
+ i.gravity 'center'
22
+ i.extent size
23
+ end
24
+ image.format File.extname(out_path).gsub(/^\./, '')
25
+ image.write(out_path)
26
+ end
27
+
28
+ # Trims extra whitespace.
29
+ # @param in_path [String] file input path
30
+ # @param out_path [String] processor output file path.
31
+ # @param options [Hash] creation options
32
+ def self.trim(in_path, out_path, _options)
33
+ MiniMagick::Tool::Convert.new do |convert|
34
+ convert << in_path
35
+ convert << "-trim"
36
+ convert << out_path
37
+ end
38
+ end
39
+
40
+ # Centers and pads image.
41
+ # @param in_path [String] file input path
42
+ # @param out_path [String] processor output file path.
43
+ # @param options [Hash] creation options
44
+ def self.center(in_path, out_path, options)
45
+ MiniMagick::Tool::Convert.new do |convert|
46
+ convert << "-size"
47
+ convert << options[:output_size].tr(' ', 'x')
48
+ convert << "xc:white"
49
+ convert << in_path
50
+ convert << "-gravity"
51
+ convert << "center"
52
+ convert << "-composite"
53
+ convert << out_path
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -10,7 +10,7 @@ module GeoConcerns
10
10
  # #param options [Hash] creation options
11
11
  # @param out_path [String] processor output file path
12
12
  def self.reproject(in_path, out_path, options)
13
- execute "env SHAPE_ENCODING= ogr2ogr -q -nln #{options[:basename]} -f 'ESRI Shapefile'"\
13
+ execute "env SHAPE_ENCODING= ogr2ogr -q -nln #{options[:id]} -f 'ESRI Shapefile'"\
14
14
  " -t_srs #{options[:output_srid]} -preserve_fid '#{out_path}' '#{in_path}'"
15
15
  end
16
16
  end
@@ -1,10 +1,25 @@
1
1
  module GeoConcerns
2
2
  module Processors
3
3
  module Raster
4
- extend ActiveSupport::Autoload
4
+ class Processor < Hydra::Derivatives::Processors::Processor
5
+ def process
6
+ raster_processor_class.new(source_path,
7
+ directives,
8
+ output_file_service: output_file_service).process
9
+ end
5
10
 
6
- eager_autoload do
7
- autoload :Processor
11
+ # Returns a raster processor class based on mime type passed in the directives object.
12
+ # @return raster processing class
13
+ def raster_processor_class
14
+ case directives.fetch(:input_format)
15
+ when 'text/plain; gdal-format=USGSDEM'
16
+ GeoConcerns::Processors::Raster::Dem
17
+ when 'application/octet-stream; gdal-format=AIG'
18
+ GeoConcerns::Processors::Raster::Aig
19
+ else
20
+ GeoConcerns::Processors::Raster::Base
21
+ end
22
+ end
8
23
  end
9
24
  end
10
25
  end
@@ -4,6 +4,7 @@ module GeoConcerns
4
4
  class Base < Hydra::Derivatives::Processors::Processor
5
5
  include Hydra::Derivatives::Processors::ShellBasedProcessor
6
6
  include GeoConcerns::Processors::BaseGeoProcessor
7
+ include GeoConcerns::Processors::Image
7
8
  include GeoConcerns::Processors::Gdal
8
9
 
9
10
  def self.encode(path, options, output_file)
@@ -0,0 +1,79 @@
1
+ require 'simpler_tiles'
2
+
3
+ module GeoConcerns
4
+ module Processors
5
+ module Rendering
6
+ extend ActiveSupport::Concern
7
+ included do
8
+ # Renders a thumbnail from a vector dataset.
9
+ # @param in_path [String] file input path
10
+ # @param out_path [String] processor output file path
11
+ # @param options [Hash] creation options
12
+ def self.vector_thumbnail(in_path, out_path, options)
13
+ map = GeoConcerns::Processors::Rendering.simple_tiles_map(in_path, options)
14
+ File.open(out_path, 'wb') { |f| f.write map.to_png }
15
+ end
16
+ end
17
+
18
+ class << self
19
+ # Builds a simple tiles map from a shapefile.
20
+ # @param in_path [String] file input path
21
+ # @param options [Hash] creation
22
+ # @return [SimplerTiles::Map] simple tiles map
23
+ def simple_tiles_map(in_path, options)
24
+ assign_rendering_options(in_path, options)
25
+ size = rendering_size(options)
26
+ SimplerTiles::Map.new do |m|
27
+ m.srs = 'EPSG:4326'
28
+ m.bgcolor = SimplerTiles.config.bg_color
29
+ m.width = size[0]
30
+ m.height = size[1]
31
+ m.set_bounds(*simple_tiles_bounds(options))
32
+ add_shapefile_layer(in_path, m)
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ # Adds a shapefile layer to a simple tiles map.
39
+ # @param in_path [String] file input path
40
+ # @param options [Hash] creation options
41
+ def add_shapefile_layer(in_path, map)
42
+ Dir.glob("#{in_path}/*.shp").each do |shp|
43
+ map.layer shp do |l|
44
+ l.query "select * from '#{File.basename shp, '.shp'}'" do |q|
45
+ q.styles SimplerTiles.config.to_h
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ # Re-orders options bounds for use with a simple tiles map.
52
+ # @param options [Hash] creation options
53
+ # @return [Array] simple tiles map bounds
54
+ def simple_tiles_bounds(options)
55
+ [options[:bounds][:east],
56
+ options[:bounds][:north],
57
+ options[:bounds][:west],
58
+ options[:bounds][:south]]
59
+ end
60
+
61
+ # Transforms the size directive into an array.
62
+ # @param options [Hash] creation options
63
+ # @return [Array] derivative size
64
+ def rendering_size(options)
65
+ options[:output_size].split(' ').map(&:to_i)
66
+ end
67
+
68
+ # Assigns new values from the vector info command to the creation options hash.
69
+ # @param in_path [String] file input path
70
+ # @param options [Hash] creation options
71
+ def assign_rendering_options(in_path, options)
72
+ vector_info = GeoConcerns::Processors::Vector::Info.new(in_path)
73
+ options[:name] = vector_info.name
74
+ options[:bounds] = vector_info.bounds
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end