Module: GDAL::Dataset::ClassMethods

Included in:
GDAL::Dataset
Defined in:
lib/gdal/dataset/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#copy_whole_raster(source, destination, options = {}, progress_function = nil) ⇒ Object

Copy all dataset raster data.

This function copies the complete raster contents of one dataset to another similarly configured dataset. The source and destination dataset must have the same number of bands, and the same width and height. The bands do not have to have the same data type.

This function is primarily intended to support implementation of driver specific CreateCopy() functions. It implements efficient copying, in particular “chunking” the copy in substantial blocks and, if appropriate, performing the transfer in a pixel interleaved fashion.

Parameters:

  • source (GDAL::Dataset, FFI::Pointer)
  • destination (GDAL::Dataset, FFI::Pointer)
  • options (Hash) (defaults to: {})
  • progress_function (Proc) (defaults to: nil)

Options Hash (options):

  • interleave: ('pixel')

    nterleave: ‘pixel’

  • compressed: (Object)

    true

  • skip_holes: (Object)

    true

Raises:



43
44
45
46
47
48
49
50
51
# File 'lib/gdal/dataset/class_methods.rb', line 43

def copy_whole_raster(source, destination, options = {}, progress_function = nil)
  source_ptr = GDAL._pointer(GDAL::Dataset, source, autorelease: false)
  dest_ptr = GDAL._pointer(GDAL::Dataset, destination, autorelease: false)
  options_ptr = GDAL::Options.pointer(options)

  GDAL::CPLErrorHandler.manually_handle("Unable to copy whole raster") do
    FFI::GDAL::GDAL.GDALDatasetCopyWholeRaster(source_ptr, dest_ptr, options_ptr, progress_function, nil)
  end
end

#new_pointer(dataset, warn_on_nil: true) ⇒ FFI::AutoPointer

Parameters:

Returns:

  • (FFI::AutoPointer)


55
56
57
58
59
# File 'lib/gdal/dataset/class_methods.rb', line 55

def new_pointer(dataset, warn_on_nil: true)
  ptr = GDAL._pointer(GDAL::Dataset, dataset, warn_on_nil: warn_on_nil, autorelease: false)

  FFI::AutoPointer.new(ptr, Dataset.method(:release))
end

#open(path, access_flag, shared: true) ⇒ Object

Parameters:

  • path (String)

    Path to the file that contains the dataset. Can be a local file or a URL.

  • access_flag (String)

    ‘r’ or ‘w’.

  • shared (Boolean) (defaults to: true)

    Whether or not to open using GDALOpenShared vs GDALOpen. Defaults to true.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gdal/dataset/class_methods.rb', line 11

def open(path, access_flag, shared: true)
  ds = new(path, access_flag, shared_open: shared)

  if block_given?
    result = yield ds
    ds.close
    result
  else
    ds
  end
end

#release(pointer) ⇒ Object

Parameters:

  • pointer (FFI::Pointer)


62
63
64
65
66
# File 'lib/gdal/dataset/class_methods.rb', line 62

def release(pointer)
  return unless pointer && !pointer.null?

  FFI::GDAL::GDAL.GDALClose(pointer)
end