Class: Map::Gdal::RasterService

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/map/gdal/raster_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_input) ⇒ RasterService

Returns a new instance of RasterService.



6
7
8
9
10
# File 'lib/map/gdal/raster_service.rb', line 6

def initialize(file_input)
  raise 'File does not exist' unless File.exist?(file_input)

  @file = file_input
end

Instance Method Details

#call(options) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/map/gdal/raster_service.rb', line 12

def call(options)
  out = get_path_to_temp_file(:raster, options[:format])
  add_to_clean(out)
  add_to_clean("#{out}.aux.xml")

  format_out = if options[:format] == 'tif'
    'GTiff'
  else
    options[:format].upcase
  end

  begin
    run_command(%{gdal_rasterize -q -of #{format_out} #{options_to_command_line(options, :format)} -l "#{get_layer_name}" "#{@file}" "#{out}"})
  rescue RuntimeError => re
    if re.message.include?('Failed to find field')
      cpg_iso = "#{get_file_name_with_path(@file)}.cpg"
      run_command(%{echo 885910 > "#{cpg_iso}"})
      retry
    elsif
      raise re
    end
  end
  out
end