Class: OpenTopo::Services::DemConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/open_topo/services/dem_converter.rb

Constant Summary collapse

FILENAME_EXT_SPLITTER =
".*"

Class Method Summary collapse

Class Method Details

.call(file, file_format, file_path: nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/open_topo/services/dem_converter.rb', line 11

def self.call(file, file_format, file_path: nil)
  if file.nil? || !File.file?(file)
    raise OpenTopo::Errors::FileError.new("File is not a file (#{file.class})", file_path: file)
  end

  new_filename = build_new_filename(file, file_path, file_format)
  original_filename = file.path

  _message, error, status = Open3.capture3(gdal_translate_command(original_filename, new_filename))

  if status.success?
    File.open(new_filename, "r")
  else
    raise OpenTopo::Errors::ConvertError, error.strip
  end
end