Module: Map::Gdal::Base
- Included in:
- ColorizeService, ConstrastStretchService, CropService, GdalInfoService, GridService, MergeService, NdviService, Ogr2ogrService, OgriInfoService, PolygonizeService, RasterService, RgbService, TilesService, TranslateService, WarpService
- Defined in:
- lib/map/gdal/base.rb
Instance Attribute Summary collapse
-
#files_to_clean ⇒ Object
readonly
Returns the value of attribute files_to_clean.
Instance Method Summary collapse
- #add_to_clean(path) ⇒ Object
- #clean ⇒ Object
-
#gdal_running?(times = nil) ⇒ Boolean
verifica se gdal está rodando checa 3 vezes fazendo um pequeno sleep entre as vezes para garantia.
- #get_file_name_with_path(file) ⇒ Object
- #get_layer_name ⇒ Object
- #get_path_to_temp_file(prefix, extension, file_id = "#{Time.current.to_i}-#{(rand * 1_000).to_i}") ⇒ Object
- #options_to_command_line(options, reject = []) ⇒ Object
- #run_command(command) ⇒ Object
- #store_kml ⇒ Object
- #tmp_file(file_name) ⇒ Object
Instance Attribute Details
#files_to_clean ⇒ Object (readonly)
Returns the value of attribute files_to_clean.
4 5 6 |
# File 'lib/map/gdal/base.rb', line 4 def files_to_clean @files_to_clean end |
Instance Method Details
#add_to_clean(path) ⇒ Object
34 35 36 37 |
# File 'lib/map/gdal/base.rb', line 34 def add_to_clean(path) @files_to_clean ||= [] @files_to_clean << path end |
#clean ⇒ Object
28 29 30 31 32 |
# File 'lib/map/gdal/base.rb', line 28 def clean @files_to_clean.to_a.compact.each do |path| FileUtils.rm_rf(path) end end |
#gdal_running?(times = nil) ⇒ Boolean
verifica se gdal está rodando checa 3 vezes fazendo um pequeno sleep entre as vezes para garantia
8 9 10 11 12 13 14 15 16 |
# File 'lib/map/gdal/base.rb', line 8 def gdal_running?(times = nil) `ps aux | grep gdal | grep -v grep` if $?.success? true elsif times.to_i < 3 sleep 0.1 gdal_running?(times.to_i + 1) end end |
#get_file_name_with_path(file) ⇒ Object
62 63 64 65 |
# File 'lib/map/gdal/base.rb', line 62 def get_file_name_with_path(file) file_name = File.basename(file, '.*' ) File.join(File.dirname(file), "#{file_name}") end |
#get_layer_name ⇒ Object
18 19 20 |
# File 'lib/map/gdal/base.rb', line 18 def get_layer_name Map::Gdal::OgriInfoService.new(@file).layer_name end |
#get_path_to_temp_file(prefix, extension, file_id = "#{Time.current.to_i}-#{(rand * 1_000).to_i}") ⇒ Object
39 40 41 |
# File 'lib/map/gdal/base.rb', line 39 def get_path_to_temp_file(prefix, extension, file_id="#{Time.current.to_i}-#{(rand * 1_000).to_i}") tmp_file("#{prefix}-#{file_id}.#{extension}") end |
#options_to_command_line(options, reject = []) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/map/gdal/base.rb', line 43 def (, reject = []) reject = [reject] unless reject.is_a?(Array) .map do |key, value| "-#{key} #{value}" unless reject.to_a.include?(key) end.compact.join(' ') end |
#run_command(command) ⇒ Object
51 52 53 54 55 |
# File 'lib/map/gdal/base.rb', line 51 def run_command(command) out = `#{command} 2>&1` raise "Falha ao rodar comando [$ #{command}]\n[#{out}]" unless $?.success? out end |
#store_kml ⇒ Object
22 23 24 25 26 |
# File 'lib/map/gdal/base.rb', line 22 def store_kml @file = get_path_to_temp_file('kml', 'kml') add_to_clean(@file) IO.write(@file, @kml) end |
#tmp_file(file_name) ⇒ Object
57 58 59 60 |
# File 'lib/map/gdal/base.rb', line 57 def tmp_file(file_name) FileUtils.mkdir_p(File.join(Dir.pwd, 'tmp')) File.join(Dir.pwd, 'tmp', file_name) end |