Class: GDAL::Utils::Warp

Inherits:
Object
  • Object
show all
Defined in:
lib/gdal/utils/warp.rb,
lib/gdal/utils/warp/options.rb

Overview

Wrapper for gdalwarp using GDALWarp C API.

Defined Under Namespace

Classes: Options

Class Method Summary collapse

Class Method Details

.perform(dst_dataset: nil, dst_dataset_path: nil, src_datasets: [], options: Options.new) {|GDAL::Dataset| ... } ⇒ GDAL::Dataset

Perform the gdalwarp (GDALWarp) operation.

Examples:

Warp a dataset (for dst_dataset_path).

src_dataset = GDAL::Dataset.open("source.tif", "r")
options = GDAL::Utils::Warp::Options.new(options: ["-t_srs", "EPSG:3857"])

dataset = GDAL::Utils::Warp.perform(
  dst_dataset_path: "destination.tif",
  src_datasets: [src_dataset],
  options: options
)

# Do something with the dataset.
puts dataset.raster_x_size

# You must close the dataset when you are done with it.
dataset.close
src_dataset.close

Warp a dataset (for dst_dataset_path) using block syntax.

src_dataset = GDAL::Dataset.open("source.tif", "r")
options = GDAL::Utils::Warp::Options.new(options: ["-t_srs", "EPSG:3857"])

GDAL::Utils::Warp.perform(
  dst_dataset_path: "destination.tif",
  src_datasets: src_dataset,
  options: options
) do |dataset|
  # Do something with the dataset.
  puts dataset.raster_x_size

  # Dataset will be closed automatically.
end
src_dataset.close

Warp a dataset (for dst_dataset).

src_dataset = GDAL::Dataset.open("source.tif", "r")
dst_dataset = GDAL::Dataset.open("destination.tif", "w") # Dataset with other projection.

GDAL::Utils::Warp.perform(dst_dataset: dst_dataset, src_datasets: [src_dataset])

# You must close the dataset when you are done with it.
dst_dataset.close
src_dataset.close

Yields:



64
65
66
67
68
69
70
# File 'lib/gdal/utils/warp.rb', line 64

def self.perform(dst_dataset: nil, dst_dataset_path: nil, src_datasets: [], options: Options.new, &block)
  if dst_dataset
    for_dataset(dst_dataset: dst_dataset, src_datasets: src_datasets, options: options)
  else
    for_dataset_path(dst_dataset_path: dst_dataset_path, src_datasets: src_datasets, options: options, &block)
  end
end