Class: GDAL::RasterBand
- Inherits:
-
Object
- Object
- GDAL::RasterBand
- Includes:
- Logger, MajorObject, AlgorithmExtensions, ColoringExtensions, Extensions, IOExtensions, GDAL::RasterBandMixins::AlgorithmMethods
- Defined in:
- lib/gdal/raster_band.rb,
lib/gdal/extensions/raster_band/extensions.rb,
lib/gdal/extensions/raster_band/io_extensions.rb,
lib/gdal/extensions/raster_band/coloring_extensions.rb,
lib/gdal/extensions/raster_band/algorithm_extensions.rb
Overview
rubocop:disable Metrics/ClassLength
Defined Under Namespace
Modules: AlgorithmExtensions, ColoringExtensions, Extensions, IOExtensions
Constant Summary collapse
- ALL_VALID =
0x01
- PER_DATASET =
0x02
- ALPHA =
0x04
- NODATA =
0x08
Instance Attribute Summary collapse
-
#c_pointer ⇒ FFI::Pointer
readonly
C pointer to the C raster band.
-
#dataset ⇒ GDAL::Dataset
readonly
The dataset that owns this RasterBand.
Instance Method Summary collapse
-
#access_flag ⇒ Symbol
The type of access to the raster band this object currently has.
- #arbitrary_overviews? ⇒ Boolean
-
#block_size ⇒ Hash{x => Integer, y => Integer}
The natural block size is the block size that is most efficient for accessing the format.
- #category_names ⇒ Array<String>
- #category_names=(names) ⇒ Object
-
#color_interpretation ⇒ Symbol
One of FFI::GDAL::GDAL::ColorInterp.
- #color_interpretation=(new_color_interp) ⇒ Object
-
#color_table ⇒ GDAL::ColorTable
Gets the associated GDAL::ColorTable.
- #color_table=(new_color_table) ⇒ Object
- #compute_statistics(approx_ok: false, &progress_block) ⇒ Hash{minimum => Float, maximum => Float, mean => Float, standard_deviation => Float}
-
#copy_whole_raster(destination_band, **options, &progress) ⇒ Boolean
Copies the contents of one raster to another similarly configure band.
- #create_mask_band(*flags) ⇒ Object
-
#data_type ⇒ Symbol
The pixel data type for this band.
-
#default_histogram(force: false, &block) {|completion, message| ... } ⇒ Hash{minimum => Float, maximum => Float, buckets => Integer, totals => Array<Integer>}
Gets the default raster histogram.
- #default_raster_attribute_table ⇒ GDAL::RasterAttributeTable
- #default_raster_attribute_table=(rat_table) ⇒ Object
-
#fill(real_value, imaginary_value = 0) ⇒ Object
Fill this band with constant value.
- #flush_cache ⇒ Object
-
#histogram(min, max, buckets, include_out_of_range: false, approx_ok: false, &block) {|completion, message| ... } ⇒ Hash{minimum => Float, maximum => Float, buckets => Integer, totals => Array<Integer>}
Computes a histogram using the given inputs.
-
#initialize(raster_band, dataset = nil) ⇒ RasterBand
constructor
A new instance of RasterBand.
- #mask_band ⇒ GDAL::RasterBand
- #mask_flags ⇒ Array<Symbol>
-
#maximum_value ⇒ Hash{value => Float, is_tight => Boolean}
The maximum value in the band, not counting NODATA values.
-
#min_max(approx_ok: false) ⇒ Hash{min => Float, max => Float}
The minimum and maximum values for this band.
-
#minimum_value ⇒ Hash{value => Float, is_tight => Boolean}
The minimum value in the band, not counting NODATA values.
-
#no_data_value ⇒ Hash{value => Float, is_associated => Boolean}
The no data value for a band is generally a special marker value used to mark pixels that are not valid data.
-
#no_data_value=(value) ⇒ Object
Sets the no data value for this band.
-
#number ⇒ Integer
The number of band within the associated dataset that this band represents.
-
#offset ⇒ Object
This value (in combination with the #scale value) is used to transform raw pixel values into the units returned by #units.
-
#offset=(new_offset) ⇒ Boolean
Sets the scaling offset.
-
#offset? ⇒ Boolean
Check if the offset is set.
- #overview(index) ⇒ GDAL::RasterBand
- #overview_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: data_type, pixel_space: 0, line_space: 0) ⇒ FFI::MemoryPointer
IO access for raster data in this band.
-
#raster_sample_overview(desired_samples = 0) ⇒ GDAL::RasterBand
Returns the most reduced overview of this RasterBand that still satisfies the deisred number of samples.
-
#read_block(x_block_number, y_block_number, image_buffer = nil) ⇒ FFI::MemoryPointer
Read a block of image data, more efficiently than #read.
-
#scale ⇒ Object
The raster value scale.
- #scale=(new_scale) ⇒ Object
-
#scale? ⇒ Boolean
Check if the scale is set.
-
#statistics(approx_ok: true, force: true) ⇒ Hash{minimum: Float, maximum: Float, mean: Float, standard_deviation: Float}
Returns minimum, maximum, mean, and standard deviation of all pixel values in this band.
- #unit_type ⇒ String
- #unit_type=(new_unit_type) ⇒ Object
- #write_block(x_block_number, y_block_number, data_pointer = nil) ⇒ Object
-
#x_size ⇒ Integer
The raster width in pixels.
-
#y_size ⇒ Integer
The raster height in pixels.
Methods included from AlgorithmExtensions
Methods included from ColoringExtensions
#colorize!, #colors_as_hex, #colors_as_rgb, #hex_to_rgb
Methods included from IOExtensions
#block_buffer_size, #block_count, #pixel_value, #read_blocks_by_block, #read_lines_by_block, #readlines, #set_pixel_value, #write_xy_narray
Methods included from Extensions
#each_overview, #overviews, #pixel_count, #projected_points, #to_a, #to_na, #to_nna
Methods included from GDAL::RasterBandMixins::AlgorithmMethods
#checksum_image, #compute_proximity!, #fill_nodata!, included, #polygonize, #sieve_filter, #sieve_filter!
Methods included from MajorObject
#all_metadata, #description, #description=, #metadata, #metadata_domain_list, #metadata_item, #null?, #set_metadata_item
Constructor Details
#initialize(raster_band, dataset = nil) ⇒ RasterBand
28 29 30 31 32 33 34 35 36 |
# File 'lib/gdal/raster_band.rb', line 28 def initialize(raster_band, dataset = nil) @c_pointer = GDAL._pointer(GDAL::RasterBand, raster_band, autorelease: false) # Init the dataset too--the dataset owns the raster band, so when the dataset # gets closed, the raster band gets cleaned up. Storing a reference to the # dataset here ensures the underlying raster band doesn't get pulled out # from under the Ruby object that represents it. @dataset = dataset || init_dataset end |
Instance Attribute Details
#c_pointer ⇒ FFI::Pointer (readonly)
22 23 24 |
# File 'lib/gdal/raster_band.rb', line 22 def c_pointer @c_pointer end |
#dataset ⇒ GDAL::Dataset (readonly)
25 26 27 |
# File 'lib/gdal/raster_band.rb', line 25 def dataset @dataset end |
Instance Method Details
#access_flag ⇒ Symbol
The type of access to the raster band this object currently has.
62 63 64 |
# File 'lib/gdal/raster_band.rb', line 62 def access_flag FFI::GDAL::GDAL.GDALGetRasterAccess(@c_pointer) end |
#arbitrary_overviews? ⇒ Boolean
178 179 180 |
# File 'lib/gdal/raster_band.rb', line 178 def arbitrary_overviews? !FFI::GDAL::GDAL.GDALHasArbitraryOverviews(@c_pointer).zero? end |
#block_size ⇒ Hash{x => Integer, y => Integer}
The natural block size is the block size that is most efficient for accessing the format. For many formats this is simply a whole scanline in which case x is set to #x_size, and y is set to 1.
122 123 124 125 126 127 128 |
# File 'lib/gdal/raster_band.rb', line 122 def block_size x_pointer = FFI::MemoryPointer.new(:int) y_pointer = FFI::MemoryPointer.new(:int) FFI::GDAL::GDAL.GDALGetBlockSize(@c_pointer, x_pointer, y_pointer) { x: x_pointer.read_int, y: y_pointer.read_int } end |
#category_names ⇒ Array<String>
131 132 133 134 135 136 |
# File 'lib/gdal/raster_band.rb', line 131 def category_names names = FFI::GDAL::GDAL.GDALGetRasterCategoryNames(@c_pointer) return [] if names.null? names.get_array_of_string(0) end |
#category_names=(names) ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/gdal/raster_band.rb', line 140 def category_names=(names) names_pointer = GDAL._string_array_to_pointer(names) GDAL::CPLErrorHandler.manually_handle("Unable to set category names") do FFI::GDAL::GDAL.GDALSetRasterCategoryNames(@c_pointer, names_pointer) end end |
#color_interpretation ⇒ Symbol
75 76 77 |
# File 'lib/gdal/raster_band.rb', line 75 def color_interpretation FFI::GDAL::GDAL.GDALGetRasterColorInterpretation(@c_pointer) end |
#color_interpretation=(new_color_interp) ⇒ Object
81 82 83 84 85 |
# File 'lib/gdal/raster_band.rb', line 81 def color_interpretation=(new_color_interp) GDAL::CPLErrorHandler.manually_handle("Unable to set color interpretation") do FFI::GDAL::GDAL.GDALSetRasterColorInterpretation(@c_pointer, new_color_interp) end end |
#color_table ⇒ GDAL::ColorTable
Gets the associated GDAL::ColorTable. Note that it remains owned by the RasterBand and cannot be modified.
91 92 93 94 95 96 97 98 |
# File 'lib/gdal/raster_band.rb', line 91 def color_table color_table_ptr = FFI::GDAL::GDAL.GDALGetRasterColorTable(@c_pointer) color_table_ptr.autorelease = false return nil if color_table_ptr.null? ColorTable.new(color_table_ptr) end |
#color_table=(new_color_table) ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/gdal/raster_band.rb', line 102 def color_table=(new_color_table) color_table_pointer = GDAL::ColorTable.new_pointer(new_color_table) GDAL::CPLErrorHandler.manually_handle("Unable to set color table") do FFI::GDAL::GDAL.GDALSetRasterColorTable(@c_pointer, color_table_pointer) end end |
#compute_statistics(approx_ok: false, &progress_block) ⇒ Hash{minimum => Float, maximum => Float, mean => Float, standard_deviation => Float}
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/gdal/raster_band.rb', line 312 def compute_statistics(approx_ok: false, &progress_block) min_ptr = FFI::MemoryPointer.new(:double) max_ptr = FFI::MemoryPointer.new(:double) mean_ptr = FFI::MemoryPointer.new(:double) standard_deviation_ptr = FFI::MemoryPointer.new(:double) GDAL::CPLErrorHandler.manually_handle("Unable to compute raster statistics") do FFI::GDAL::GDAL::GDALComputeRasterStatistics( @c_pointer, # hBand approx_ok, # bApproxOK min_ptr, # pdfMin max_ptr, # pdfMax mean_ptr, # pdfMean standard_deviation_ptr, # pdfStdDev progress_block, # pfnProgress nil # pProgressData ) end { minimum: min_ptr.read_double, maximum: max_ptr.read_double, mean: mean_ptr.read_double, standard_deviation: standard_deviation_ptr.read_double } end |
#copy_whole_raster(destination_band, **options, &progress) ⇒ Boolean
Copies the contents of one raster to another similarly configure band. The two bands must have the same width and height but do not have to be the same data type.
Options:
* :compressed
* 'YES': forces alignment on the destination_band to achieve the best
compression.
595 596 597 598 599 600 601 602 603 604 605 606 |
# File 'lib/gdal/raster_band.rb', line 595 def copy_whole_raster(destination_band, **, &progress) destination_pointer = GDAL._pointer(GDAL::RasterBand, destination_band) = GDAL::Options.pointer() GDAL::CPLErrorHandler.manually_handle("Unable to copy whole raster") do FFI::GDAL::GDAL.GDALRasterBandCopyWholeRaster(@c_pointer, destination_pointer, , progress, nil) end end |
#create_mask_band(*flags) ⇒ Object
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/gdal/raster_band.rb', line 241 def create_mask_band(*flags) flag_value = 0 flag_value = flags.each_with_object(flag_value) do |flag, result| 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 GDAL::CPLErrorHandler.manually_handle("Unable to create mask band") do FFI::GDAL::GDAL.GDALCreateMaskBand(@c_pointer, flag_value) end end |
#data_type ⇒ Symbol
The pixel data type for this band.
113 114 115 |
# File 'lib/gdal/raster_band.rb', line 113 def data_type FFI::GDAL::GDAL.GDALGetRasterDataType(@c_pointer) end |
#default_histogram(force: false, &block) {|completion, message| ... } ⇒ Hash{minimum => Float, maximum => Float, buckets => Integer, totals => Array<Integer>}
Gets the default raster histogram. Results are returned as a Hash so some metadata about the histogram can be returned. Example:
{
:minimum => -0.9,
:maximum => 255.9,
:buckets => 256,
:totals => [
3954, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 0,
0, 0, 10, 27, 201, 699, 1766, 3472, 5013, 6464, 7698, 8352,
9039, 10054, 11378, 13132, 14377, 14371, 14221, 14963, 14740,
14379, 13724, 12938, 11318, 9828, 8504, 7040, 5700, 4890,
4128, 3276, 2749, 2322, 1944, 1596, 1266, 1050, 784, 663,
547, 518, 367, 331, 309, 279, 178, 169, 162, 149, 109, 98,
90, 89, 82, 85, 74, 75, 42, 40, 39, 35, 39, 36, 36, 27, 20,
12, 13, 19, 16, 12, 11, 6, 6, 8, 12, 6, 8, 11, 3, 7, 9, 2,
5, 2, 5, 1, 4, 0, 0, 1, 0, 1, 2, 1, 0, 2, 1, 0, 0, 1, 0, 1,
1, 1, 0, 2, 1, 2, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
]
}
Also, you can pass a block to get status on the processing. Conforms to FFI::GDAL::GDAL::GDALProgressFunc.
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 |
# File 'lib/gdal/raster_band.rb', line 484 def default_histogram(force: false, &block) min_pointer = FFI::MemoryPointer.new(:double) max_pointer = FFI::MemoryPointer.new(:double) buckets_pointer = FFI::MemoryPointer.new(:int) histogram_pointer = FFI::MemoryPointer.new(:pointer) progress_proc = block || nil handler = GDAL::CPLErrorHandler.new handler.on_warning = proc {} handler.on_none = proc do min = min_pointer.read_double max = max_pointer.read_double buckets = buckets_pointer.read_int totals = if buckets.zero? [] else histogram_pointer.get_pointer(0).read_array_of_int(buckets) end { minimum: min, maximum: max, buckets: buckets, totals: totals } end handler.custom_handle do FFI::GDAL::GDAL.GDALGetDefaultHistogram( @c_pointer, min_pointer, max_pointer, buckets_pointer, histogram_pointer, force, progress_proc, nil ) end end |
#default_raster_attribute_table ⇒ GDAL::RasterAttributeTable
427 428 429 430 431 432 |
# File 'lib/gdal/raster_band.rb', line 427 def default_raster_attribute_table rat_pointer = FFI::GDAL::GDAL.GDALGetDefaultRAT(@c_pointer) return nil if rat_pointer.null? GDAL::RasterAttributeTable.new(rat_pointer) end |
#default_raster_attribute_table=(rat_table) ⇒ Object
435 436 437 438 439 440 441 |
# File 'lib/gdal/raster_band.rb', line 435 def default_raster_attribute_table=(rat_table) rat_table_ptr = GDAL::RasterAttributeTable.new_pointer(rat_table) GDAL::CPLErrorHandler.manually_handle("Unable to set default raster attribute table") do FFI::GDAL::GDAL.GDALSetDefaultRAT(@c_pointer, rat_table_ptr) end end |
#fill(real_value, imaginary_value = 0) ⇒ Object
Fill this band with constant value. Useful for clearing a band and setting to a default value.
265 266 267 268 269 |
# File 'lib/gdal/raster_band.rb', line 265 def fill(real_value, imaginary_value = 0) GDAL::CPLErrorHandler.manually_handle("Unable to fill raster") do FFI::GDAL::GDAL.GDALFillRaster(@c_pointer, real_value, imaginary_value) end end |
#flush_cache ⇒ Object
39 40 41 42 43 |
# File 'lib/gdal/raster_band.rb', line 39 def flush_cache GDAL::CPLErrorHandler.manually_handle("Unable to flush cache") do FFI::GDAL::GDAL.GDALFlushRasterCache(@c_pointer) end end |
#histogram(min, max, buckets, include_out_of_range: false, approx_ok: false, &block) {|completion, message| ... } ⇒ Hash{minimum => Float, maximum => Float, buckets => Integer, totals => Array<Integer>}
Computes a histogram using the given inputs. If you just want the default histogram, use #default_histogram.
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 |
# File 'lib/gdal/raster_band.rb', line 547 def histogram(min, max, buckets, include_out_of_range: false, approx_ok: false, &block) histogram_pointer = FFI::MemoryPointer.new(:pointer, buckets) progress_proc = block || nil handler = GDAL::CPLErrorHandler.new handler.on_warning = proc {} handler.on_none = proc do totals = if buckets.zero? [] else histogram_pointer.read_array_of_int(buckets) end { minimum: min, maximum: max, buckets: buckets, totals: totals } end handler.custom_handle do FFI::GDAL::GDAL.GDALGetRasterHistogram(@c_pointer, min.to_f, max.to_f, buckets, histogram_pointer, include_out_of_range, approx_ok, progress_proc, nil) end end |
#mask_band ⇒ GDAL::RasterBand
210 211 212 213 214 215 |
# File 'lib/gdal/raster_band.rb', line 210 def mask_band band_pointer = FFI::GDAL::GDAL.GDALGetMaskBand(@c_pointer) return nil if band_pointer.null? self.class.new(band_pointer) end |
#mask_flags ⇒ Array<Symbol>
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/gdal/raster_band.rb', line 218 def mask_flags flag_list = FFI::GDAL::GDAL.GDALGetMaskFlags(@c_pointer).to_s(2).scan(/\d/) flags = [] flag_list.reverse_each.with_index do |flag, i| flag = flag.to_i if i.zero? && flag == 1 flags << :GMF_ALL_VALID elsif i == 1 && flag == 1 flags << :GMF_PER_DATASET elsif i == 2 && flag == 1 flags << :GMF_ALPHA elsif i == 3 && flag == 1 flags << :GMF_NODATA end end flags end |
#maximum_value ⇒ Hash{value => Float, is_tight => Boolean}
The maximum value in the band, not counting NODATA values. For file formats that don’t know this intrinsically, the maximum supported value for the data type will generally be returned.
750 751 752 753 754 755 |
# File 'lib/gdal/raster_band.rb', line 750 def maximum_value is_tight = FFI::MemoryPointer.new(:bool) value = FFI::GDAL::GDAL.GDALGetRasterMaximum(@c_pointer, is_tight) { value: value, is_tight: is_tight.read_bytes(1).to_bool } end |
#min_max(approx_ok: false) ⇒ Hash{min => Float, max => Float}
The minimum and maximum values for this band.
724 725 726 727 728 729 |
# File 'lib/gdal/raster_band.rb', line 724 def min_max(approx_ok: false) min_max = FFI::MemoryPointer.new(:double, 2) FFI::GDAL::GDAL.GDALComputeRasterMinMax(@c_pointer, approx_ok, min_max) { min: min_max[0].read_double, max: min_max[1].read_double } end |
#minimum_value ⇒ Hash{value => Float, is_tight => Boolean}
The minimum value in the band, not counting NODATA values. For file formats that don’t know this intrinsically, the minimum supported value for the data type will generally be returned.
737 738 739 740 741 742 |
# File 'lib/gdal/raster_band.rb', line 737 def minimum_value is_tight = FFI::MemoryPointer.new(:bool) value = FFI::GDAL::GDAL.GDALGetRasterMinimum(@c_pointer, is_tight) { value: value, is_tight: is_tight.read_bytes(1).to_bool } end |
#no_data_value ⇒ Hash{value => Float, is_associated => Boolean}
The no data value for a band is generally a special marker value used to mark pixels that are not valid data. Such pixels should generally not be displayed, nor contribute to analysis operations.
153 154 155 156 157 158 159 |
# File 'lib/gdal/raster_band.rb', line 153 def no_data_value associated = FFI::MemoryPointer.new(:bool) value = FFI::GDAL::GDAL.GDALGetRasterNoDataValue(@c_pointer, associated) value = nil if value.to_d == BigDecimal("-10_000_000_000.0") { value: value, is_associated: associated.read_bytes(1).to_bool } end |
#no_data_value=(value) ⇒ Object
Sets the no data value for this band. Do nothing if attempting to set to nil, because removing a no data value is impossible until GDAL 2.1.
166 167 168 169 170 |
# File 'lib/gdal/raster_band.rb', line 166 def no_data_value=(value) GDAL::CPLErrorHandler.manually_handle("Unable to set NODATA value") do FFI::GDAL::GDAL.GDALSetRasterNoDataValue(@c_pointer, value) end end |
#number ⇒ Integer
The number of band within the associated dataset that this band represents.
70 71 72 |
# File 'lib/gdal/raster_band.rb', line 70 def number FFI::GDAL::GDAL.GDALGetBandNumber(@c_pointer) end |
#offset ⇒ Object
This value (in combination with the #scale value) is used to transform raw pixel values into the units returned by #units. For example this might be used to store elevations in GUInt16 bands with a precision of 0.1, and starting from -100.
Units value = (raw value * scale) + offset.
For file formats that don’t know this intrinsically a value of 0.0 is returned.
381 382 383 |
# File 'lib/gdal/raster_band.rb', line 381 def offset FFI::GDAL::GDAL.GDALGetRasterOffset(@c_pointer, nil) end |
#offset=(new_offset) ⇒ Boolean
Sets the scaling offset. Very few formats support this method.
397 398 399 400 401 |
# File 'lib/gdal/raster_band.rb', line 397 def offset=(new_offset) GDAL::CPLErrorHandler.manually_handle("Unable to set raster offset") do FFI::GDAL::GDAL.GDALSetRasterOffset(@c_pointer, new_offset) end end |
#offset? ⇒ Boolean
Check if the offset is set.
387 388 389 390 391 |
# File 'lib/gdal/raster_band.rb', line 387 def offset? success = FFI::MemoryPointer.new(:bool) FFI::GDAL::GDAL.GDALGetRasterOffset(@c_pointer, success) success.read_bytes(1).to_bool end |
#overview(index) ⇒ GDAL::RasterBand
184 185 186 187 188 189 190 191 |
# File 'lib/gdal/raster_band.rb', line 184 def overview(index) return nil if overview_count.zero? overview_pointer = FFI::GDAL::GDAL.GDALGetOverview(@c_pointer, index) return nil if overview_pointer.null? self.class.new(overview_pointer) end |
#overview_count ⇒ Integer
173 174 175 |
# File 'lib/gdal/raster_band.rb', line 173 def overview_count FFI::GDAL::GDAL.GDALGetOverviewCount(@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: data_type, pixel_space: 0, line_space: 0) ⇒ FFI::MemoryPointer
IO access for raster data in this band. Default values are set up to operate on one line at a time, keeping the same aspect ratio.
On buffers… You can use different size buffers from the original x and y size to allow for resampling. Using larger buffers will upsample the raster data; smaller buffers will downsample it.
On pixel_space
and line_space
.… These values control how data is organized in the buffer.
rubocop:disable Metrics/ParameterLists
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 |
# File 'lib/gdal/raster_band.rb', line 651 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: data_type, pixel_space: 0, line_space: 0) return unless @c_pointer x_size ||= self.x_size y_size ||= self.y_size buffer_x_size ||= x_size buffer_y_size ||= y_size buffer ||= GDAL._pointer_from_data_type(buffer_data_type, buffer_x_size * buffer_y_size) FFI::GDAL::GDAL.GDALRasterIO( @c_pointer, GDAL._gdal_access_flag(access_flag), x_offset, y_offset, x_size, y_size, buffer, buffer_x_size, buffer_y_size, buffer_data_type, pixel_space, line_space ) buffer end |
#raster_sample_overview(desired_samples = 0) ⇒ GDAL::RasterBand
Returns the most reduced overview of this RasterBand that still satisfies the deisred number of samples. Using 0 fetches the most reduced overview. If the band doesn’t have any overviews or none of the overviews have enough samples, it will return the same band.
202 203 204 205 206 207 |
# File 'lib/gdal/raster_band.rb', line 202 def raster_sample_overview(desired_samples = 0) band_pointer = FFI::GDAL::GDAL.GDALGetRasterSampleOverview(@c_pointer, desired_samples) return nil if band_pointer.null? self.class.new(band_pointer) end |
#read_block(x_block_number, y_block_number, image_buffer = nil) ⇒ FFI::MemoryPointer
Read a block of image data, more efficiently than #read. Doesn’t resample or do data type conversion.
695 696 697 698 699 700 701 702 703 |
# File 'lib/gdal/raster_band.rb', line 695 def read_block(x_block_number, y_block_number, image_buffer = nil) image_buffer ||= FFI::MemoryPointer.new(:buffer_out, block_buffer_size) GDAL::CPLErrorHandler.manually_handle("Unable to read block") do FFI::GDAL::GDAL.GDALReadBlock(@c_pointer, x_block_number, y_block_number, image_buffer) end image_buffer end |
#scale ⇒ Object
The raster value scale. This value (in combination with the #offset value) is used to transform raw pixel values into the units returned by #units. For example this might be used to store elevations in GUInt16 bands with a precision of 0.1, and starting from -100.
Units value = (raw value * scale) + offset
For file formats that don’t know this intrinsically a value of one is returned.
350 351 352 |
# File 'lib/gdal/raster_band.rb', line 350 def scale FFI::GDAL::GDAL.GDALGetRasterScale(@c_pointer, nil) end |
#scale=(new_scale) ⇒ Object
364 365 366 367 368 |
# File 'lib/gdal/raster_band.rb', line 364 def scale=(new_scale) GDAL::CPLErrorHandler.manually_handle("Unable to set raster scale") do FFI::GDAL::GDAL.GDALSetRasterScale(@c_pointer, new_scale.to_f) end end |
#scale? ⇒ Boolean
Check if the scale is set.
356 357 358 359 360 |
# File 'lib/gdal/raster_band.rb', line 356 def scale? success = FFI::MemoryPointer.new(:bool) FFI::GDAL::GDAL.GDALGetRasterScale(@c_pointer, success) success.read_bytes(1).to_bool end |
#statistics(approx_ok: true, force: true) ⇒ Hash{minimum: Float, maximum: Float, mean: Float, standard_deviation: Float}
Returns minimum, maximum, mean, and standard deviation of all pixel values in this band.
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/gdal/raster_band.rb', line 280 def statistics(approx_ok: true, force: true) min = FFI::MemoryPointer.new(:double) max = FFI::MemoryPointer.new(:double) mean = FFI::MemoryPointer.new(:double) standard_deviation = FFI::MemoryPointer.new(:double) handler = GDAL::CPLErrorHandler.new handler.on_warning = proc { {} } handler.on_none = proc do { minimum: min.read_double, maximum: max.read_double, mean: mean.read_double, standard_deviation: standard_deviation.read_double } end handler.custom_handle do FFI::GDAL::GDAL.GDALGetRasterStatistics(@c_pointer, approx_ok, force, min, max, mean, standard_deviation) end end |
#unit_type ⇒ String
404 405 406 407 408 409 410 |
# File 'lib/gdal/raster_band.rb', line 404 def unit_type # The returned string should not be modified, nor freed by the calling application. type, ptr = FFI::GDAL::GDAL.GDALGetRasterUnitType(@c_pointer) ptr.autorelease = false type end |
#unit_type=(new_unit_type) ⇒ Object
415 416 417 418 419 420 421 422 423 424 |
# File 'lib/gdal/raster_band.rb', line 415 def unit_type=(new_unit_type) unless defined? FFI::GDAL::GDAL::GDALSetRasterUnitType warn "GDALSetRasterUnitType is not defined. Can't call RasterBand#unit_type=" return end GDAL::CPLErrorHandler.manually_handle("Unable to set unit type") do FFI::GDAL::GDAL.GDALSetRasterUnitType(@c_pointer, new_unit_type) end end |
#write_block(x_block_number, y_block_number, data_pointer = nil) ⇒ Object
711 712 713 714 715 716 717 718 719 |
# File 'lib/gdal/raster_band.rb', line 711 def write_block(x_block_number, y_block_number, data_pointer = nil) data_pointer ||= FFI::Buffer.alloc_inout(block_buffer_size) GDAL::CPLErrorHandler.manually_handle("Unable to write block") do FFI::GDAL::GDAL.GDALWriteBlock(@c_pointer, x_block_number, y_block_number, data_pointer) end data_pointer end |