Module: GDAL::Dataset::RasterBandMethods
- Included in:
- GDAL::Dataset
- Defined in:
- lib/gdal/dataset/raster_band_methods.rb
Class Method Summary collapse
-
.parse_mask_flag_symbols(*flags) ⇒ Integer
Lets you pass in :GMF_ symbols that represent mask band flags and bitwise ors them.
- .valid_min_buffer_size(buffer_data_type, x_buffer_size, y_buffer_size) ⇒ Integer
Instance Method Summary collapse
- #add_band(type, **options) ⇒ GDAL::RasterBand?
-
#create_mask_band(*flags) ⇒ Object
Adds a mask band to the dataset.
- #raster_band(raster_index) ⇒ GDAL::RasterBand
- #raster_count ⇒ Integer
-
#raster_io(access_flag, buffer = nil, x_size: nil, y_size: nil, x_offset: 0, y_offset: 0, buffer_x_size: nil, buffer_y_size: nil, buffer_data_type: nil, band_numbers: nil, pixel_space: 0, line_space: 0, band_space: 0) ⇒ FFI::MemoryPointer
rubocop:disable Metrics/ParameterLists.
- #raster_x_size ⇒ Integer?
- #raster_y_size ⇒ Integer?
Class Method Details
.parse_mask_flag_symbols(*flags) ⇒ Integer
Lets you pass in :GMF_ symbols that represent mask band flags and bitwise ors them.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/gdal/dataset/raster_band_methods.rb', line 13 def self.parse_mask_flag_symbols(*flags) flags.reduce(0) do |result, flag| result | case flag when :GMF_ALL_VALID then 0x01 when :GMF_PER_DATASET then 0x02 when :GMF_PER_ALPHA then 0x04 when :GMF_NODATA then 0x08 else 0 end end end |
.valid_min_buffer_size(buffer_data_type, x_buffer_size, y_buffer_size) ⇒ Integer
29 30 31 32 33 |
# File 'lib/gdal/dataset/raster_band_methods.rb', line 29 def self.valid_min_buffer_size(buffer_data_type, x_buffer_size, y_buffer_size) data_type_bytes = GDAL::DataType.size(buffer_data_type) / 8 data_type_bytes * x_buffer_size * y_buffer_size end |
Instance Method Details
#add_band(type, **options) ⇒ GDAL::RasterBand?
73 74 75 76 77 78 79 80 81 |
# File 'lib/gdal/dataset/raster_band_methods.rb', line 73 def add_band(type, **) = GDAL::Options.pointer() GDAL::CPLErrorHandler.manually_handle("Unable to add band") do FFI::GDAL::GDAL.GDALAddBand(@c_pointer, type, ) end raster_band(raster_count) end |
#create_mask_band(*flags) ⇒ Object
Adds a mask band to the dataset.
87 88 89 90 91 92 93 |
# File 'lib/gdal/dataset/raster_band_methods.rb', line 87 def create_mask_band(*flags) flag_value = RasterBandMethods.parse_mask_flag_symbols(flags) GDAL::CPLErrorHandler.manually_handle("Unable to create Dataset mask band") do FFI::GDAL::GDAL.GDALCreateDatasetMaskBand(@c_pointer, flag_value) end end |
#raster_band(raster_index) ⇒ GDAL::RasterBand
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/gdal/dataset/raster_band_methods.rb', line 58 def raster_band(raster_index) if raster_index > raster_count raise GDAL::InvalidRasterBand, "Invalid raster band number '#{raster_index}'. Must be <= #{raster_count}" end raster_band_ptr = FFI::GDAL::GDAL.GDALGetRasterBand(@c_pointer, raster_index) raster_band_ptr.autorelease = false GDAL::RasterBand.new(raster_band_ptr, self) end |
#raster_count ⇒ Integer
50 51 52 53 54 |
# File 'lib/gdal/dataset/raster_band_methods.rb', line 50 def raster_count return 0 if null? FFI::GDAL::GDAL.GDALGetRasterCount(@c_pointer) end |
#raster_io(access_flag, buffer = nil, x_size: nil, y_size: nil, x_offset: 0, y_offset: 0, buffer_x_size: nil, buffer_y_size: nil, buffer_data_type: nil, band_numbers: nil, pixel_space: 0, line_space: 0, band_space: 0) ⇒ FFI::MemoryPointer
rubocop:disable Metrics/ParameterLists
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/gdal/dataset/raster_band_methods.rb', line 132 def raster_io(access_flag, buffer = nil, x_size: nil, y_size: nil, x_offset: 0, y_offset: 0, buffer_x_size: nil, buffer_y_size: nil, buffer_data_type: nil, band_numbers: nil, pixel_space: 0, line_space: 0, band_space: 0) x_size ||= raster_x_size y_size ||= raster_y_size buffer_x_size ||= x_size buffer_y_size ||= y_size buffer_data_type ||= raster_band(1).data_type band_numbers_ptr, band_count = InternalFunctions.band_numbers_args(band_numbers) band_count = raster_count if band_count.zero? buffer ||= GDAL._pointer_from_data_type(buffer_data_type, buffer_x_size * buffer_y_size * band_count) gdal_access_flag = GDAL._gdal_access_flag(access_flag) min_buffer_size = RasterBandMethods.valid_min_buffer_size(buffer_data_type, buffer_x_size, buffer_y_size) unless buffer.size >= min_buffer_size raise GDAL::BufferTooSmall, "Buffer size (#{buffer.size}) too small (#{min_buffer_size})" end GDAL::CPLErrorHandler.manually_handle("Unable to perform raster band IO") do FFI::GDAL::GDAL::GDALDatasetRasterIO( @c_pointer, # hDS gdal_access_flag, # eRWFlag x_offset, # nXOff y_offset, # nYOff x_size, # nXSize y_size, # nYSize buffer, # pData buffer_x_size, # nBufXSize buffer_y_size, # nBufYSize buffer_data_type, # eBufType band_count, # nBandCount band_numbers_ptr, # panBandMap (WTH is this?) pixel_space, # nPixelSpace line_space, # nLineSpace band_space # nBandSpace ) end buffer end |