Class: GDAL::Dataset

Inherits:
Object
  • Object
show all
Extended by:
ClassMethods
Includes:
Accessors, AlgorithmMethods, Extensions, Matching, RasterBandMethods, WarpMethods, Logger, MajorObject
Defined in:
lib/gdal/dataset.rb,
lib/gdal/dataset/matching.rb,
lib/gdal/dataset/accessors.rb,
lib/gdal/dataset/warp_methods.rb,
lib/gdal/dataset/class_methods.rb,
lib/gdal/dataset/algorithm_methods.rb,
lib/gdal/dataset/internal_functions.rb,
lib/gdal/dataset/raster_band_methods.rb,
lib/gdal/extensions/dataset/extensions.rb

Overview

A set of associated raster bands and info common to them all. It’s also responsible for the georeferencing transform and coordinate system definition of all bands.

Defined Under Namespace

Modules: Accessors, AlgorithmMethods, ClassMethods, Extensions, InternalFunctions, Matching, RasterBandMethods, WarpMethods

Constant Summary collapse

ACCESS_FLAGS =
{
  "r" => :GA_ReadOnly,
  "w" => :GA_Update
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ClassMethods

copy_whole_raster, new_pointer, open, release

Methods included from Extensions

#blue_band, #contains_geometry?, #each_band, #extent, #find_band, #green_band, #raster_bands, #red_band, #to_na, #to_vector, #undefined_band

Methods included from WarpMethods

#create_and_reproject_image, #reproject_image

Methods included from AlgorithmMethods

#rasterize_geometries!, #rasterize_layers!, #simple_image_warp, #suggested_warp_output, #suggested_warp_output2

Methods included from Matching

#compute_matching_points

Methods included from RasterBandMethods

#add_band, #create_mask_band, parse_mask_flag_symbols, #raster_band, #raster_count, #raster_io, #raster_x_size, #raster_y_size, valid_min_buffer_size

Methods included from Accessors

#driver, #gcp_count, #gcp_projection, #gcps, #geo_transform, #geo_transform=, #projection, #projection=, #spatial_reference

Methods included from MajorObject

#all_metadata, #description, #metadata, #metadata_domain_list, #metadata_item, #null?, #set_metadata_item

Constructor Details

#initialize(path_or_pointer, access_flag, shared_open: true) ⇒ Dataset

Returns a new instance of Dataset.

Parameters:

  • path_or_pointer (String, FFI::Pointer)

    Path to the file that contains the dataset or a pointer to the dataset. If it’s a path, it can be a local file or a URL.

  • access_flag (String)

    ‘r’ or ‘w’.

  • shared_open (Boolean) (defaults to: true)

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

Raises:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/gdal/dataset.rb', line 48

def initialize(path_or_pointer, access_flag, shared_open: true)
  @c_pointer =
    if path_or_pointer.is_a? String
      if shared_open
        FFI::GDAL::GDAL.GDALOpenShared(path_or_pointer, ACCESS_FLAGS[access_flag])
      else
        FFI::GDAL::GDAL.GDALOpen(path_or_pointer, ACCESS_FLAGS[access_flag])
      end
    else
      path_or_pointer
    end

  raise OpenFailure, path_or_pointer if @c_pointer.null?

  @geo_transform = nil
  @spatial_reference = nil
end

Instance Attribute Details

#c_pointerFFI::Pointer (readonly)

Returns Pointer to the GDALDatasetH that’s represented by this Ruby object.

Returns:

  • (FFI::Pointer)

    Pointer to the GDALDatasetH that’s represented by this Ruby object.



40
41
42
# File 'lib/gdal/dataset.rb', line 40

def c_pointer
  @c_pointer
end

Instance Method Details

#access_flagSymbol

Returns:

  • (Symbol)


74
75
76
77
78
# File 'lib/gdal/dataset.rb', line 74

def access_flag
  flag = FFI::GDAL::GDAL.GDALGetAccess(@c_pointer)

  FFI::GDAL::GDAL::Access[flag]
end

#build_overviews(resampling, overview_levels, band_numbers: nil, &progress) ⇒ Object

Parameters:

  • resampling (String, Symbol)

    One of:

    • :nearest - Nearest neighbor resampling

    • :gauss - Gaussian kernel resampling

    • :cubic - Cubic convolution resampling

    • :average - Average of all non-NODATA

    • :mode - Selects the value that occurs most often

    • :average_magphase - Averages complex data in mag/phase space

    • :none

  • overview_levels (Array<Integer>)

    The list of overview decimation factors to build.

  • band_numbers (Array<Integer>) (defaults to: nil)

    The numbers of the bands to build overviews from.

Raises:

See Also:



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/gdal/dataset.rb', line 111

def build_overviews(resampling, overview_levels, band_numbers: nil, &progress)
  resampling_string = case resampling
                      when String
                        resampling.upcase
                      when Symbol
                        resampling.to_s.upcase
                      end

  overview_levels_ptr = FFI::MemoryPointer.new(:int, overview_levels.size)
  overview_levels_ptr.write_array_of_int(overview_levels)
  band_numbers_ptr, band_count = InternalFunctions.band_numbers_args(band_numbers)

  GDAL::CPLErrorHandler.manually_handle("Unable to build overviews") do
    FFI::GDAL::GDAL.GDALBuildOverviews(
      @c_pointer,
      resampling_string,
      overview_levels.size,
      overview_levels_ptr,
      band_count,
      band_numbers_ptr,
      progress,
      nil
    )
  end
end

#closeObject

Close the dataset.



67
68
69
70
71
# File 'lib/gdal/dataset.rb', line 67

def close
  Dataset.release(@c_pointer)

  @c_pointer = nil
end

#file_listArray<String>

Fetches all files that form the dataset.

Returns:



82
83
84
85
86
87
88
89
90
# File 'lib/gdal/dataset.rb', line 82

def file_list
  list_pointer = FFI::GDAL::GDAL.GDALGetFileList(@c_pointer)
  return [] if list_pointer.null?

  file_list = list_pointer.get_array_of_string(0)
  FFI::CPL::String.CSLDestroy(list_pointer)

  file_list
end

#flush_cacheObject

Flushes all write-cached data to disk.



93
94
95
# File 'lib/gdal/dataset.rb', line 93

def flush_cache
  FFI::GDAL::GDAL.GDALFlushCache(@c_pointer)
end