Class: Map::Gdal::CropService
- Inherits:
-
Object
- Object
- Map::Gdal::CropService
- Includes:
- Base
- Defined in:
- lib/map/gdal/crop_service.rb
Instance Attribute Summary
Attributes included from Base
Instance Method Summary collapse
- #call(options = {}) ⇒ Object
-
#initialize(tif) ⇒ CropService
constructor
A new instance of CropService.
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(tif) ⇒ CropService
Returns a new instance of CropService.
6 7 8 |
# File 'lib/map/gdal/crop_service.rb', line 6 def initialize(tif) @tif = tif end |
Instance Method Details
#call(options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/map/gdal/crop_service.rb', line 10 def call( = {}) raise 'Reference file is not defined' unless [: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([:reference]).to_xml) run_command(%{ogr2ogr -f "ESRI Shapefile" #{shp_folder} #{kml}}) service = Map::Gdal::WarpService.new(@tif) = { '-config': 'GDALWARP_IGNORE_BAD_CUTLINE YES', crop_to_cutline: '', cutline: shp_folder } [:dstalpha] = [:dstalpha] if [:dstalpha] [:dstnodata] = [:dstnodata] if [:dstnodata] [:s_srs] = [:s_srs] if [:s_srs] [:tr] = [:tr].gsub('-tr ', '') if [:tr] out = service.call() add_to_clean(out) out end |