Class: Map::Gdal::GridService

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/map/gdal/grid_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(kml) ⇒ GridService

Returns a new instance of GridService.



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

def initialize(kml)
  @kml = kml
  store_kml
end

Instance Method Details

#call(options = {}) ⇒ Object



11
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/grid_service.rb', line 11

def call(options = {})
  raise 'Invalid field' unless options[:field]

  out = get_path_to_temp_file('out', 'kml')
  where = options[:where] ? "-where \"#{options[:where]}\"" : ''
  algorithm = options[:algorithm] ? "-a #{options[:algorithm]}" : ''

  run_command(
    %{
      gdal_grid
        -q
        #{algorithm}
        #{where}
        -zfield "#{options[:field]}"
        -of GTiff
        -ot Float64
        -l "#{get_layer_name}"
        #{@file}
        #{out}
    }.squish
  )

  add_to_clean(out)
  out
end