Class: GDAL::Utils::DEM

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

Overview

Wrapper for gdaldem using GDALDEMProcessing C API.

Defined Under Namespace

Classes: Options

Class Method Summary collapse

Class Method Details

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

Perform the gdaldem (GDALDEMProcessing) operation.

Examples:

Create a raster dataset.

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

dataset = GDAL::Utils::DEM.perform(
  dst_dataset_path: "destination.tif",
  src_dataset: src_dataset,
  processing: "hillshade"
)

# 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 for color-relief.

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

dataset = GDAL::Utils::DEM.perform(
  dst_dataset_path: "destination.tif",
  src_dataset: src_dataset,
  processing: "color-relief",
  color_filename: "color.txt"
)

# 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")
options = GDAL::Utils::DEM::Options.new(options: ["-of", "GTiff", "-co", "TILED=YES"])

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

Create a raster dataset using block syntax.

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

GDAL::Utils::DEM.perform(
  dst_dataset_path: "destination.tif",
  src_dataset: src_dataset,
  processing: "hillshade"
) do |dataset|
  # Do something with the dataset.
  puts dataset.raster_x_size

  # Dataset will be closed automatically.
end
src_dataset.close

Parameters:

  • dst_dataset_path (String)

    The path to the destination dataset.

  • src_dataset (OGR::DataSource)

    The source dataset.

  • processing (String)

    The processing type (one of “hillshade”, “slope”, “aspect”, “color-relief”, “TRI”, “TPI”, “Roughness”).

  • color_filename (String) (defaults to: nil)

    color file (mandatory for “color-relief” processing, should be NULL otherwise).

  • options (GDAL::Utils::DEM::Options) (defaults to: Options.new)

    Options.

Yields:

Returns:

  • (GDAL::Dataset)

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

Raises:



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/gdal/utils/dem.rb', line 90

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

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

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