Sha256: 7416bbd65f5417ca387b679e819a8f5e3f6297520e33a5e61b124087db81a192
Contents?: true
Size: 1.01 KB
Versions: 8
Compression:
Stored size: 1.01 KB
Contents
# frozen_string_literal: true require 'zip' class Map::Gdal::PolygonizeService include Map::Gdal::Base def initialize(tif_path) @tif_path = tif_path end def call(options = {}) if options[:kml] @tif_path = Map::Gdal::CropService.new(@tif_path).call(reference: IO.binread(options[:kml])) add_to_clean(@tif_path) end file_id = "#{Time.current.to_i}-#{(rand * 1_000).to_i}" destination_shp = get_path_to_temp_file('shapefile', 'shp', file_id) zip_file = get_path_to_temp_file('shapefile', 'zip', file_id) run_command(%{gdal_polygonize.py #{@tif_path} -f "ESRI Shapefile" #{destination_shp}}) Zip::File.open(zip_file, Zip::File::CREATE) do |zip| %w(dbf prj shp shx).each do |extension| file_name = "shapefile-#{file_id}.#{extension}" file_with_path = get_path_to_temp_file('shapefile', extension, file_id) zip.add(file_name, file_with_path) add_to_clean(file_with_path) end end add_to_clean(zip_file) zip_file end end
Version data entries
8 entries across 8 versions & 1 rubygems