Class: GDAL::Utils::Grid

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

Overview

Wrapper for gdal_grid using GDALGrid C API.

Defined Under Namespace

Classes: Options

Class Method Summary collapse

Class Method Details

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

Perform the gdal_grid (GDALGrid) operation.

Examples:

Create a raster dataset.

src_dataset = GDAL::Dataset.open("source.tif", "r")
dataset = GDAL::Utils::Grid.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

Create a raster dataset with options.

src_dataset = GDAL::Dataset.open("source.tif", "r")
dataset = GDAL::Utils::Grid.perform(
  dst_dataset_path: "destination.tif",
  src_dataset: src_dataset,
  options: GDAL::Utils::Grid::Options.new(options: ["-of", "GTiff", "-co", "COMPRESS=DEFLATE"])
)

# 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

Create a raster dataset using block syntax.

src_dataset = GDAL::Dataset.open("source.tif", "r")
GDAL::Utils::Grid.perform(dst_dataset_path: "destination.tif", src_dataset: src_dataset) do |dataset|
  # Do something with the dataset.
  puts dataset.raster_x_size

  # Dataset will be closed automatically.
end
src_dataset.close

Parameters:

Yields:

Returns:

  • (GDAL::Dataset)

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

Raises:



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/gdal/utils/grid.rb', line 56

def self.perform(dst_dataset_path:, src_dataset:, options: Options.new, &block)
  result_code_ptr = ::FFI::MemoryPointer.new(:int)
  dst_dataset_ptr = ::FFI::GDAL::Utils.GDALGrid(
    dst_dataset_path,
    src_dataset.c_pointer,
    options.c_pointer,
    result_code_ptr
  )
  success = result_code_ptr.read_int.zero?

  raise ::GDAL::Error, "GDALGrid failed." if dst_dataset_ptr.null? || !success

  ::GDAL::Dataset.open(dst_dataset_ptr, "w", &block)
end