Class: GDAL::Utils::Nearblack

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

Overview

Wrapper for nearblack using GDALNearblack C API.

Defined Under Namespace

Classes: Options

Class Method Summary collapse

Class Method Details

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

Perform the nearblack (GDALNearblack) operation.

Examples:

Perform nearblack on dataset (for dst_dataset_path).

src_dataset = GDAL::Dataset.open("source.tif", "r")

dataset = GDAL::Utils::Nearblack.perform(dst_dataset_path: "destination.tif", src_dataset: src_dataset)

# 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

Perform nearblack on dataset with options (for dst_dataset_path).

src_dataset = GDAL::Dataset.open("source.tif", "r")
options = GDAL::Utils::Nearblack::Options.new(options: ["-near", "10"])

dataset = GDAL::Utils::Nearblack.perform(
  dst_dataset_path: "destination.tif",
  src_dataset: 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

Perform nearblack on dataset (for dst_dataset_path) using block syntax.

src_dataset = GDAL::Dataset.open("source.tif", "r")
options = GDAL::Utils::Nearblack::Options.new(options: ["-near", "10"])

GDAL::Utils::Nearblack.perform(
  dst_dataset_path: "destination.tif",
  src_dataset: 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

Perform nearblack on dataset (for dst_dataset).

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

GDAL::Utils::Nearblack.perform(dst_dataset: dst_dataset, src_dataset: src_dataset)

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

Parameters:

Yields:

Returns:

  • (GDAL::Dataset)

    The destination dataset (only if block is not specified; dataset must be closed).



76
77
78
79
80
81
82
# File 'lib/gdal/utils/nearblack.rb', line 76

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