Class: GDAL::Dataset
- Inherits:
-
Object
- Object
- GDAL::Dataset
- 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
-
#c_pointer ⇒ FFI::Pointer
readonly
Pointer to the GDALDatasetH that’s represented by this Ruby object.
Instance Method Summary collapse
- #access_flag ⇒ Symbol
- #build_overviews(resampling, overview_levels, band_numbers: nil, &progress) ⇒ Object
-
#close ⇒ Object
Close the dataset.
-
#file_list ⇒ Array<String>
Fetches all files that form the dataset.
-
#flush_cache ⇒ Object
Flushes all write-cached data to disk.
-
#initialize(path_or_pointer, access_flag, shared_open: true) ⇒ Dataset
constructor
A new instance of Dataset.
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
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, #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.
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_pointer ⇒ FFI::Pointer (readonly)
40 41 42 |
# File 'lib/gdal/dataset.rb', line 40 def c_pointer @c_pointer end |
Instance Method Details
#access_flag ⇒ 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
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 |
#close ⇒ Object
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_list ⇒ Array<String>
Fetches all files that form the dataset.
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 |