geo_works-derivatives 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +22 -0
  5. data/.travis.yml +21 -0
  6. data/Gemfile +7 -0
  7. data/LICENSE.txt +15 -0
  8. data/README.md +63 -0
  9. data/Rakefile +7 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/config/simpler_tiles.yml +24 -0
  13. data/geo_works-derivatives.gemspec +42 -0
  14. data/lib/geo_works/derivatives/config.rb +78 -0
  15. data/lib/geo_works/derivatives/processors/base_geo_processor.rb +92 -0
  16. data/lib/geo_works/derivatives/processors/gdal.rb +72 -0
  17. data/lib/geo_works/derivatives/processors/image.rb +67 -0
  18. data/lib/geo_works/derivatives/processors/ogr.rb +22 -0
  19. data/lib/geo_works/derivatives/processors/raster/aig.rb +43 -0
  20. data/lib/geo_works/derivatives/processors/raster/base.rb +44 -0
  21. data/lib/geo_works/derivatives/processors/raster/dem.rb +32 -0
  22. data/lib/geo_works/derivatives/processors/raster/info.rb +69 -0
  23. data/lib/geo_works/derivatives/processors/raster.rb +34 -0
  24. data/lib/geo_works/derivatives/processors/rendering.rb +82 -0
  25. data/lib/geo_works/derivatives/processors/vector/base.rb +47 -0
  26. data/lib/geo_works/derivatives/processors/vector/info.rb +89 -0
  27. data/lib/geo_works/derivatives/processors/vector/shapefile.rb +23 -0
  28. data/lib/geo_works/derivatives/processors/vector.rb +31 -0
  29. data/lib/geo_works/derivatives/processors/zip.rb +32 -0
  30. data/lib/geo_works/derivatives/processors.rb +15 -0
  31. data/lib/geo_works/derivatives/runners/raster_derivatives.rb +12 -0
  32. data/lib/geo_works/derivatives/runners/vector_derivatives.rb +12 -0
  33. data/lib/geo_works/derivatives/runners.rb +9 -0
  34. data/lib/geo_works/derivatives/version.rb +6 -0
  35. data/lib/geo_works/derivatives.rb +12 -0
  36. metadata +188 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c40b9537076d66f4122e6436a4275d1e3bd26b43b4eebe86b8937709069e7c49
4
+ data.tar.gz: 713e155b39436bf6e2fe324ca5b033d4a8404e7cc27fc6e1e3ff204646e7e80d
5
+ SHA512:
6
+ metadata.gz: 35b8607ddc30dc5f10fd8e0203a73c5746f362b1e0fa6f8d6c80ca0c9ee9654cfd16d39589fe2922ed42256abcb3be407bafa6e6785bdd0f8aeed9f54b157f4c
7
+ data.tar.gz: 3a9fb91fb9160dddef57b8a87606b6e6308361401b111d2ca6bd699db28022f685a12a4f50d949e8834f4068f1596f9c545fbb1e10f659dc3a0c1c4c7e1f95fb
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ .byebug_history
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,22 @@
1
+ inherit_gem:
2
+ bixby: bixby_default.yml
3
+ AllCops:
4
+ DisplayCopNames: true
5
+ TargetRubyVersion: 2.3
6
+ Exclude:
7
+ - 'bin/*'
8
+ - 'vendor/**/*'
9
+ Metrics/BlockLength:
10
+ Exclude:
11
+ - 'spec/**/*'
12
+ - 'lib/geo_works/derivatives/processors/gdal.rb'
13
+ - 'lib/geo_works/derivatives/processors/image.rb'
14
+ - 'lib/geo_works/derivatives/specs/**/*'
15
+ - 'lib/tasks/**/*'
16
+ - 'db/schema.rb'
17
+ - 'Rakefile'
18
+ - '*.gemspec'
19
+ Naming/FileName:
20
+ Exclude:
21
+ - "geo_works-derivatives.gemspec"
22
+ - "Gemfile"
data/.travis.yml ADDED
@@ -0,0 +1,21 @@
1
+ sudo: true
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.5
5
+ addons:
6
+ apt:
7
+ packages:
8
+ - libgdal1i
9
+ - libgdal-dev
10
+ - gdal-bin
11
+ - libcairo2-dev
12
+ - libpango1.0-dev
13
+ before_install:
14
+ - git clone https://github.com/propublica/simple-tiles.git
15
+ - cd simple-tiles
16
+ - ./configure && make
17
+ - sudo make install
18
+ - cd ..
19
+ - gem install bundler -v 1.16.1
20
+ before_script:
21
+ - gdalinfo --version
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+ source 'https://rubygems.org'
3
+
4
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
5
+
6
+ # Specify your gem's dependencies in geo_derivatives.gemspec
7
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,15 @@
1
+ ##########################################################################
2
+ # Copyright 2018 Princeton University Library
3
+ # Additional copyright may be held by others, as reflected in the commit log
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # GeoWorks::Derivatives
2
+
3
+ [![Build Status](https://img.shields.io/travis/pulibrary/geo_works-derivatives/master.svg)](https://travis-ci.org/pulibrary/geo_works-derivatives)
4
+
5
+ Hydra::Derivatives compatible processors for Geospatial derivative generation.
6
+
7
+ ## Dependencies
8
+
9
+ 1. [ImageMagick](http://www.imagemagick.org/)
10
+ 1. [GDAL](http://www.gdal.org/)
11
+ * You can install it on Mac OSX with `brew install gdal`.
12
+ * On Ubuntu, use `sudo apt-get install gdal-bin`.
13
+
14
+ ## Simple Tiles
15
+
16
+ GeoWorks requires the image generation library [Simple Tiles](http://propublica.github.io/simple-tiles/).
17
+
18
+ Mac OS X:
19
+
20
+ - Install via Homebrew: ```brew install simple-tiles```
21
+
22
+ Linux:
23
+
24
+ - Install dependencies:
25
+
26
+ ```
27
+ libgdal-dev
28
+ libcairo2-dev
29
+ libpango1.0-dev
30
+ ```
31
+
32
+ - Compile:
33
+
34
+ ```
35
+ $ git clone git@github.com:propublica/simple-tiles.git
36
+ $ cd simple-tiles
37
+ $ ./configure
38
+ $ make && make install
39
+ ```
40
+
41
+ ## Installation
42
+
43
+ Add this line to your application's Gemfile:
44
+
45
+ ```ruby
46
+ gem 'geo_works-derivatives'
47
+ ```
48
+
49
+ And then execute:
50
+
51
+ $ bundle
52
+
53
+ Or install it yourself as:
54
+
55
+ $ gem install geo_works-derivatives
56
+
57
+ ## Usage
58
+
59
+ TODO: Write usage instructions here
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pulibrary/geo_works-derivatives.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'geo_works/derivatives'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,24 @@
1
+ # Background color
2
+ # Use '#ffffff' for a solid white background.
3
+ # Add two zeros to a six digit hex color code
4
+ # for a png (does not work with jpeg) image
5
+ # with a transparent background.
6
+ bg_color: '#ffffff00'
7
+
8
+ # The fill color for each shape
9
+ fill: '#e4e3ea'
10
+
11
+ # The stroke color for each line
12
+ stroke: '#483d8b'
13
+
14
+ # Width of line in pixels
15
+ weight: '0.3'
16
+
17
+ # How lines are ended, one of: "butt", "round", "square"
18
+ line_cap: 'square'
19
+
20
+ # How lines are joined together, one of: "miter", "round", "bevel"
21
+ line_join: 'miter'
22
+
23
+ # For point rendering only, the radius in pixels of the circle
24
+ radius: '2'
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "geo_works/derivatives/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'geo_works-derivatives'
9
+ spec.version = GeoWorks::Derivatives::VERSION
10
+ spec.authors = ['Eliot Jordan']
11
+ spec.email = ['eliotj@princeton.edu']
12
+
13
+ spec.summary = 'Geospatial derivative generation'
14
+ spec.description = 'Hydra::Derivatives compatible processors for Geospatial derivative generation'
15
+ spec.homepage = 'https://github.com/pulibrary/geo_works-derivatives'
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise 'RubyGems 2.0 or newer is required to protect against ' \
23
+ # 'public gem pushes.'
24
+ # end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.add_dependency 'hydra-derivatives'
34
+ spec.add_dependency 'mime-types'
35
+ spec.add_dependency 'simpler-tiles'
36
+
37
+ spec.add_development_dependency 'bixby'
38
+ spec.add_development_dependency 'bundler', '~> 1.16'
39
+ spec.add_development_dependency 'coveralls'
40
+ spec.add_development_dependency 'rake', '~> 10.0'
41
+ spec.add_development_dependency 'rspec', '~> 3.0'
42
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+ module GeoWorks
3
+ module Derivatives
4
+ module Config
5
+ class << self
6
+ def rendering_config
7
+ @config ||= RenderingConfiguration.new
8
+ end
9
+ end
10
+
11
+ class RenderingConfiguration
12
+ attr_reader :settings
13
+ attr_writer :bg_color,
14
+ :fill,
15
+ :stroke,
16
+ :weight,
17
+ :line_cap,
18
+ :line_join,
19
+ :radius
20
+
21
+ def initialize
22
+ @settings ||= File.exist?(config_file) ? YAML.load_file(config_file) : {}
23
+ end
24
+
25
+ def config_file
26
+ File.join(config_root_path, 'config/simpler_tiles.yml')
27
+ end
28
+
29
+ def config_root_path
30
+ if defined?(Rails) && Rails.root
31
+ Rails.root
32
+ else
33
+ Pathname.new(Dir.pwd)
34
+ end
35
+ end
36
+
37
+ def to_h
38
+ {
39
+ 'stroke' => stroke,
40
+ 'line-cap' => line_cap,
41
+ 'line-join' => line_join,
42
+ 'weight' => weight,
43
+ 'fill' => fill,
44
+ 'radius' => radius
45
+ }
46
+ end
47
+
48
+ def bg_color
49
+ @bg_color ||= settings.fetch('bg_color', '#ffffff00')
50
+ end
51
+
52
+ def fill
53
+ @fill ||= settings.fetch('fill', '#e4e3ea')
54
+ end
55
+
56
+ def stroke
57
+ @stroke ||= settings.fetch('stroke', '#483d8b')
58
+ end
59
+
60
+ def weight
61
+ @weight ||= settings.fetch('weight', '0.3')
62
+ end
63
+
64
+ def line_cap
65
+ @line_cap ||= settings.fetch('line_cap', 'square')
66
+ end
67
+
68
+ def line_join
69
+ @line_join ||= settings.fetch('line_join', 'miter')
70
+ end
71
+
72
+ def radius
73
+ @radius ||= settings.fetch('radius', '2')
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+ module GeoWorks
3
+ module Derivatives
4
+ module Processors
5
+ module BaseGeoProcessor
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ # Chains together and recursively runs a set of commands.
10
+ # Except for the last command in the queue, a temp file
11
+ # is created as output and is then fed into the input of the next.
12
+ # Temp files are deleted in reverse order after the last command
13
+ # is run. The commands must have the same method signature:
14
+ # command_name(in_path, out_path, options)
15
+ #
16
+ # @param in_path [String] file input path
17
+ # @param out_path [String] processor output file path
18
+ # @param method_queue [Array] set of commands to run
19
+ # @param options [Hash] creation options to pass
20
+ # rubocop:disable Metrics/MethodLength
21
+ def self.run_commands(in_path, out_path, method_queue, options)
22
+ next_step = method_queue.shift
23
+ temp = temp_path(out_path)
24
+ begin
25
+ if method_queue.empty?
26
+ method(next_step).call(in_path, out_path, options)
27
+ else
28
+ method(next_step).call(in_path, temp, options)
29
+ run_commands(temp, out_path, method_queue, options)
30
+ FileUtils.rm_rf(temp)
31
+ end
32
+ rescue => e
33
+ FileUtils.rm_rf(in_path) if Dir.exist?(in_path)
34
+ FileUtils.rm_rf(temp) if Dir.exist?(temp)
35
+ raise e
36
+ end
37
+ end
38
+ # rubocop:enable Metrics/MethodLength
39
+
40
+ # Returns a path to an intermediate temp file or directory.
41
+ # @param path [String] input file path to base temp path on
42
+ # @return [String] tempfile path
43
+ def self.temp_path(path)
44
+ time = (Time.now.to_f * 1000).to_i
45
+ "#{File.dirname(path)}/#{File.basename(path, File.extname(path))}_#{time}"
46
+ end
47
+ end
48
+
49
+ def options_for(_format)
50
+ {
51
+ label: label,
52
+ output_size: output_size,
53
+ output_srid: output_srid,
54
+ basename: basename,
55
+ id: id
56
+ }
57
+ end
58
+
59
+ # Returns the label directive or an empty string.
60
+ # @return [Sting] output label
61
+ def label
62
+ directives.fetch(:label, '')
63
+ end
64
+
65
+ # Transforms the size directive into a GDAL size parameter.
66
+ # @return [String] derivative size
67
+ def output_size
68
+ return unless directives[:size]
69
+ directives[:size].tr('x', ' ')
70
+ end
71
+
72
+ # Gets srid for reprojection derivative or returns WGS 84.
73
+ # @return [String] spatial reference code
74
+ def output_srid
75
+ directives.fetch(:srid, 'EPSG:4326')
76
+ end
77
+
78
+ # Extracts the base file name (without extension) from the source file path.
79
+ # @return [String] base file name for source
80
+ def basename
81
+ File.basename(source_path, File.extname(source_path))
82
+ end
83
+
84
+ # Gets the fileset id or returns nil.
85
+ # @return [String] fileset id
86
+ def id
87
+ directives.fetch(:id, nil)
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GeoWorks
4
+ module Derivatives
5
+ module Processors
6
+ module Gdal
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ # Executes a gdal_translate command. Used to translate a raster
11
+ # format into a different format. Also used in generating thumbnails
12
+ # from vector data.
13
+ # @param in_path [String] file input path
14
+ # @param out_path [String] processor output file path
15
+ # @param options [Hash] creation options
16
+ def self.translate(in_path, out_path, _options)
17
+ execute "gdal_translate -q -ot Byte -of GTiff -co TILED=YES -expand rgb -co COMPRESS=DEFLATE \"#{in_path}\" #{out_path}"
18
+ rescue StandardError
19
+ # Try without expanding rgb
20
+ execute "gdal_translate -q -ot Byte -of GTiff -co TILED=YES -co COMPRESS=DEFLATE \"#{in_path}\" #{out_path}"
21
+ end
22
+
23
+ # Executes a gdalwarp command. Used to transform a raster
24
+ # from one projection into another.
25
+ # @param in_path [String] file input path
26
+ # @param out_path [String] processor output file path
27
+ # @param options [Hash] creation options
28
+ def self.warp(in_path, out_path, options)
29
+ execute "gdalwarp -q -t_srs #{options[:output_srid]} "\
30
+ "#{in_path} #{out_path} -co TILED=YES -co COMPRESS=NONE"
31
+ end
32
+
33
+ # Executes a gdal_translate command. Used to compress
34
+ # a previously uncompressed raster.
35
+ # @param in_path [String] file input path
36
+ # @param out_path [String] processor output file path
37
+ # @param options [Hash] creation options
38
+ def self.compress(in_path, out_path, options)
39
+ execute "gdal_translate -q -ot Byte -a_srs #{options[:output_srid]} "\
40
+ "#{in_path} #{out_path} -co COMPRESS=JPEG -co JPEG_QUALITY=90"
41
+ end
42
+
43
+ # Executes gdaladdo and gdal_translate commands. Used to add internal overviews
44
+ # and then compress a previously uncompressed raster.
45
+ # Output will be a Cloud Optimized GeoTIFF.
46
+ # @param in_path [String] file input path
47
+ # @param out_path [String] processor output file path
48
+ # @param options [Hash] creation options
49
+ def self.cloud_optimized_geotiff(in_path, out_path, _options)
50
+ system("gdaladdo -q -r average #{in_path} 2 4 8 16 32")
51
+ execute("gdal_translate -q -expand rgb #{in_path} #{out_path} -co TILED=YES "\
52
+ "-co COMPRESS=JPEG -co COPY_SRC_OVERVIEWS=YES")
53
+ rescue StandardError
54
+ # Try without expanding rgb
55
+ execute("gdal_translate -q #{in_path} #{out_path} -co TILED=YES "\
56
+ "-co COMPRESS=JPEG -co COPY_SRC_OVERVIEWS=YES")
57
+ end
58
+
59
+ # Executes a gdal_rasterize command. Used to rasterize vector
60
+ # format into raster format.
61
+ # @param in_path [String] file input path
62
+ # #param options [Hash] creation options
63
+ # @param out_path [String] processor output file path
64
+ def self.rasterize(in_path, out_path, options)
65
+ execute "gdal_rasterize -q -burn 0 -init 255 -ot Byte -ts "\
66
+ "#{options[:output_size]} -of GTiff #{in_path} #{out_path}"
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+ require 'mini_magick'
3
+
4
+ module GeoWorks
5
+ module Derivatives
6
+ module Processors
7
+ module Image
8
+ extend ActiveSupport::Concern
9
+ included do
10
+ # Uses imagemagick to resize an image and convert it to the output format.
11
+ # Keeps the aspect ratio of the original image and adds padding to
12
+ # to the output image. The file extension is the output format.
13
+ # @param in_path [String] file input path
14
+ # @param out_path [String] processor output file path.
15
+ # @param options [Hash] creation options
16
+ # @option options [String] `:output_size` as "w h" or "wxh"
17
+ def self.convert(in_path, out_path, options)
18
+ size = options[:output_size].tr(' ', 'x')
19
+ convert = MiniMagick::Tool::Convert.new(whiny: false)
20
+ convert << in_path
21
+ convert << "-resize"
22
+ convert << size
23
+ convert << "-extent"
24
+ convert << size
25
+ convert << "-background"
26
+ convert << "white"
27
+ convert << "-gravity"
28
+ convert << "center"
29
+ convert << out_path
30
+
31
+ # suppress stderr b/c geotiffs return 'unknown field' warnings
32
+ convert.call { |_stdout, _stderr| }
33
+ end
34
+
35
+ # Trims extra whitespace.
36
+ # @param in_path [String] file input path
37
+ # @param out_path [String] processor output file path.
38
+ # @param options [Hash] creation options
39
+ def self.trim(in_path, out_path, _options)
40
+ MiniMagick::Tool::Convert.new do |convert|
41
+ convert << in_path
42
+ convert << "-trim"
43
+ convert << out_path
44
+ end
45
+ end
46
+
47
+ # Centers and pads image.
48
+ # @param in_path [String] file input path
49
+ # @param out_path [String] processor output file path.
50
+ # @param options [Hash] creation options
51
+ def self.center(in_path, out_path, options)
52
+ MiniMagick::Tool::Convert.new do |convert|
53
+ convert << "-size"
54
+ convert << options[:output_size].tr(' ', 'x')
55
+ convert << "xc:white"
56
+ convert << in_path
57
+ convert << "-gravity"
58
+ convert << "center"
59
+ convert << "-composite"
60
+ convert << out_path
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ module GeoWorks
3
+ module Derivatives
4
+ module Processors
5
+ module Ogr
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ # Executes a ogr2ogr command. Used to reproject a
10
+ # vector dataset and save the output as a shapefile
11
+ # @param in_path [String] file input path
12
+ # #param options [Hash] creation options
13
+ # @param out_path [String] processor output file path
14
+ def self.reproject(in_path, out_path, options)
15
+ execute "env SHAPE_ENCODING= ogr2ogr -q -nln #{options[:id]} -f 'ESRI Shapefile'"\
16
+ " -t_srs #{options[:output_srid]} -preserve_fid '#{out_path}' '#{in_path}'"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+ module GeoWorks
3
+ module Derivatives
4
+ module Processors
5
+ module Raster
6
+ class Aig < GeoWorks::Derivatives::Processors::Raster::Base
7
+ include GeoWorks::Derivatives::Processors::Zip
8
+
9
+ def self.encode(path, options, output_file)
10
+ unzip(path, output_file) do |zip_path|
11
+ info = Info.new(zip_path)
12
+ options[:min_max] = info.min_max
13
+ case options[:label]
14
+ when :thumbnail
15
+ encode_raster(zip_path, output_file, options)
16
+ when :display_raster
17
+ reproject_raster(zip_path, output_file, options)
18
+ end
19
+ end
20
+ end
21
+
22
+ # Set of commands to run to reproject the AIG.
23
+ # @return [Array] set of command name symbols
24
+ def self.reproject_queue
25
+ [:warp, :translate, :compress]
26
+ end
27
+
28
+ # Executes a gdal_translate command to translate a raster
29
+ # format into a different format with a scaling options. This command
30
+ # scales the min and max values of the raster into the 0 to 255 range.
31
+ # Scale is inverted (255 to 0) to create a better visualization.
32
+ # @param in_path [String] file input path
33
+ # @param out_path [String] processor output file path
34
+ # @param options [Hash] creation options
35
+ def self.translate(in_path, out_path, options)
36
+ execute "gdal_translate -scale #{options[:min_max]} 255 0 "\
37
+ "-q -ot Byte -of GTiff \"#{in_path}\" #{out_path}"
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end