Class: Map::Gdal::TranslateService

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/map/gdal/translate_service.rb

Instance Attribute Summary

Attributes included from Base

#files_to_clean

Instance Method Summary collapse

Methods included from Base

#add_to_clean, #clean, #gdal_running?, #get_file_name_with_path, #get_layer_name, #get_path_to_temp_file, #options_to_command_line, #run_command, #store_kml, #tmp_file

Constructor Details

#initialize(file) ⇒ TranslateService

Returns a new instance of TranslateService.



6
7
8
# File 'lib/map/gdal/translate_service.rb', line 6

def initialize(file)
  @file = file
end

Instance Method Details

#call(options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/map/gdal/translate_service.rb', line 26

def call(options = {})
  out = get_path_to_temp_file(:translate, options[:of])

  run_command("gdal_translate #{options_to_command_line(options)} #{@file} #{out}")

  add_to_clean(out)
  add_to_clean("#{out}.aux.xml")
  add_to_clean(out.gsub('.jpg', '.wld'))

  out
end

#to_jpeg(options = {}) ⇒ Object



19
20
21
22
23
24
# File 'lib/map/gdal/translate_service.rb', line 19

def to_jpeg(options = {})
  self.call(options.merge({
    of: 'JPEG',
    co: 'worldfile=yes'
  }))
end

#to_png(options = {}) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/map/gdal/translate_service.rb', line 10

def to_png(options = {})
  self.call(options.merge({
    of: 'PNG',
    co: 'worldfile=yes',
    scale: '',
    ot: 'Byte'
  }))
end