Sha256: e9e18c4ab7748c48907d05d4f131bc0cac284f65280a650a548efd36aa45f356

Contents?: true

Size: 1.08 KB

Versions: 8

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

class Map::Gdal::CropService
  include Map::Gdal::Base

  def initialize(tif)
    @tif = tif
  end

  def call(options = {})
    raise 'Reference file is not defined' unless options[:reference]
    shp_folder = File.join(Dir.tmpdir, "shp-#{(Time.current.to_i * rand).to_i}")
    kml = get_path_to_temp_file('table-color', 'kml')
    add_to_clean(shp_folder)
    add_to_clean(kml)

    IO.write(kml, Map::KmlEditService.new(options[:reference]).to_xml)
    run_command(%{ogr2ogr -f "ESRI Shapefile" #{shp_folder} #{kml}})
    service = Map::Gdal::WarpService.new(@tif)
    options_to_warp = {
      '-config': 'GDALWARP_IGNORE_BAD_CUTLINE YES',
      crop_to_cutline: '',
      cutline: shp_folder
    }

    options_to_warp[:dstalpha] = options[:dstalpha] if options[:dstalpha]
    options_to_warp[:dstnodata] = options[:dstnodata] if options[:dstnodata]
    options_to_warp[:s_srs] = options[:s_srs] if options[:s_srs]
    options_to_warp[:tr] = options[:tr].gsub('-tr ', '') if options[:tr]
    out = service.call(options_to_warp)
    add_to_clean(out)

    out
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
aqila-mapas-0.4.12 lib/map/gdal/crop_service.rb
aqila-mapas-0.4.11 lib/map/gdal/crop_service.rb
aqila-mapas-0.4.9 lib/map/gdal/crop_service.rb
aqila-mapas-0.4.8 lib/map/gdal/crop_service.rb
aqila-mapas-0.4.7 lib/map/gdal/crop_service.rb
aqila-mapas-0.4.6 lib/map/gdal/crop_service.rb
aqila-mapas-0.4.5 lib/map/gdal/crop_service.rb
aqila-mapas-0.4.4 lib/map/gdal/crop_service.rb