class GDAL::RasterAttributeTable

Attributes

c_pointer[R]

@return [FFI::Pointer] The C pointer that represents the C RAT.

Public Class Methods

from_color_table(color_table) click to toggle source

Create an object from a ColorTable.

@param color_table [GDAL::ColorTable, FFI::Pointer] @return [GDAL::RasterAttributeTable] @raise [GDAL::Error]

# File lib/gdal/raster_attribute_table.rb, line 12
def self.from_color_table(color_table)
  color_table_ptr = GDAL._pointer(GDAL::ColorTable, color_table, autorelease: false)
  rat_ptr = FFI::GDAL::GDAL.GDALCreateRasterAttributeTable

  GDAL::CPLErrorHandler.manually_handle("Unable to initialize from ColorTable") do
    FFI::GDAL::GDAL.GDALRATInitializeFromColorTable(rat_ptr, color_table_ptr)
  end

  new(rat_ptr)
end
new(pointer = nil) click to toggle source

@param pointer [FFI::Pointer]

# File lib/gdal/raster_attribute_table.rb, line 42
def initialize(pointer = nil)
  @c_pointer = pointer || FFI::GDAL::GDAL.GDALCreateRasterAttributeTable
end
new_pointer(raster_attribute_table) click to toggle source

@param raster_attribute_table [GDAL::RasterAttributeTable] @return [FFI::AutoPointer]

# File lib/gdal/raster_attribute_table.rb, line 25
def self.new_pointer(raster_attribute_table)
  ptr = GDAL._pointer(GDAL::Dataset, raster_attribute_table, autorelease: false)

  FFI::AutoPointer.new(ptr, RasterAttributeTable.method(:release))
end
release(pointer) click to toggle source

@param pointer [FFI::Pointer]

# File lib/gdal/raster_attribute_table.rb, line 32
def self.release(pointer)
  return unless pointer && !pointer.null?

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

Public Instance Methods

changes_written_to_file?() click to toggle source

true if the changes made to this RAT have been written to the associated dataset.

@return [Boolean]

# File lib/gdal/raster_attribute_table.rb, line 66
def changes_written_to_file?
  FFI::GDAL::GDAL.GDALRATChangesAreWrittenToFile(@c_pointer)
end
clone() click to toggle source

Clone using the C API.

@return [GDAL::RasterAttributeTable]

# File lib/gdal/raster_attribute_table.rb, line 55
def clone
  rat_ptr = FFI::GDAL::GDAL.GDALRATClone(@c_pointer)
  return nil if rat_ptr.nil? || rat_ptr.null?

  self.class.new(rat_ptr)
end
column_count() click to toggle source

@return [Integer]

# File lib/gdal/raster_attribute_table.rb, line 71
def column_count
  FFI::GDAL::GDAL.GDALRATGetColumnCount(@c_pointer)
end
column_name(index) click to toggle source

@param index [Integer] The column number. @return [String]

# File lib/gdal/raster_attribute_table.rb, line 77
def column_name(index)
  name, ptr = FFI::GDAL::GDAL.GDALRATGetNameOfCol(@c_pointer, index)
  ptr.autorelease = false

  name
end
Also aliased as: name_of_col
column_of_usage(field_usage) click to toggle source

@param field_usage [GDALRATFieldUsage] @return [Integer] The column number or nil.

# File lib/gdal/raster_attribute_table.rb, line 101
def column_of_usage(field_usage)
  column_number = FFI::GDAL::GDAL.GDALRATGetColOfUsage(@c_pointer, field_usage)
  return if column_number.negative?

  column_number
end
column_type(index) click to toggle source

@param index [Integer] The column number. @return [GDALRATFieldType]

# File lib/gdal/raster_attribute_table.rb, line 94
def column_type(index)
  FFI::GDAL::GDAL.GDALRATGetTypeOfCol(@c_pointer, index)
end
Also aliased as: type_of_col
column_usage(index) click to toggle source

@param index [Integer] The column number. @return [GDALRATFieldUsage]

# File lib/gdal/raster_attribute_table.rb, line 87
def column_usage(index)
  FFI::GDAL::GDAL.GDALRATGetUsageOfCol(@c_pointer, index)
end
Also aliased as: usage_of_col
create_column(name, type, usage) click to toggle source

@param name [String] @param type [FFI::GDAL::GDALRATFieldType] @param usage [FFI::GDAL::GDALRATFieldUsage] @raise [GDAL::Error]

# File lib/gdal/raster_attribute_table.rb, line 112
def create_column(name, type, usage)
  GDAL::CPLErrorHandler.manually_handle("Unable to create column") do
    FFI::GDAL::GDAL.GDALRATCreateColumn(@c_pointer, name, type, usage)
  end
end
destroy!() click to toggle source
# File lib/gdal/raster_attribute_table.rb, line 46
def destroy!
  RasterAttributeTable.release(@c_pointer)

  @c_pointer = nil
end
dump_readable(file_path = nil) click to toggle source

@param file_path [String] Without giving a file_path, dumps to STDOUT.

# File lib/gdal/raster_attribute_table.rb, line 221
def dump_readable(file_path = nil)
  file_ptr = file_path ? FFI::CPL::Conv.CPLOpenShared(file_path, "w", false) : nil
  FFI::GDAL::GDAL.GDALRATDumpReadable(@c_pointer, file_ptr)
  FFI::CPL::Conv.CPLCloseShared(file_ptr) if file_ptr
end
linear_binning() click to toggle source

@return [Hash{row_0_minimum => Float, bin_size => Float}]

# File lib/gdal/raster_attribute_table.rb, line 189
def linear_binning
  row_0_min_ptr = FFI::MemoryPointer.new(:double)
  bin_size_ptr = FFI::MemoryPointer.new(:double)
  result = FFI::GDAL::GDAL.GDALRATGetLinearBinning(@c_pointer, row_0_min_ptr, bin_size_ptr)
  return unless result

  {
    row_0_minimum: row_0_min_ptr.read_double,
    bin_size: bin_size_ptr.read_double
  }
end
name_of_col(index)
Alias for: column_name
row_count() click to toggle source

@return [Integer] The number of rows.

# File lib/gdal/raster_attribute_table.rb, line 119
def row_count
  FFI::GDAL::GDAL.GDALRATGetRowCount(@c_pointer)
end
row_count=(count) click to toggle source

@return [Integer] The number of rows.

# File lib/gdal/raster_attribute_table.rb, line 124
def row_count=(count)
  FFI::GDAL::GDAL.GDALRATSetRowCount(@c_pointer, count)
end
row_of_value(pixel_value) click to toggle source

Get the row for a pixel value.

@param pixel_value [Float] @return [Integer] Index of the row or nil.

# File lib/gdal/raster_attribute_table.rb, line 132
def row_of_value(pixel_value)
  row_index = FFI::GDAL::GDAL.GDALRATGetRowOfValue(@c_pointer, pixel_value)
  return if row_index.negative?

  row_index
end
set_linear_binning(row_0_minimum, bin_size) click to toggle source

@param row_0_minimum [Float] @param bin_size [Float] @raise [GDAL::Error]

# File lib/gdal/raster_attribute_table.rb, line 204
def set_linear_binning(row_0_minimum, bin_size)
  GDAL::CPLErrorHandler.manually_handle("Unable to set linear binning") do
    FFI::GDAL::GDAL.GDALRATSetLinearBinning(@c_pointer, row_0_minimum, bin_size)
  end
end
set_value_as_double(row, field, value) click to toggle source

@param row [Integer] @param field [Integer] @param value [Float]

# File lib/gdal/raster_attribute_table.rb, line 175
def set_value_as_double(row, field, value)
  FFI::GDAL::GDAL.GDALRATSetValueAsDouble(@c_pointer, row, field, value)
end
Also aliased as: set_value_as_float
set_value_as_float(row, field, value)
Alias for: set_value_as_double
set_value_as_int(row, field, value)
set_value_as_integer(row, field, value) click to toggle source

@param row [Integer] @param field [Integer] @param value [Integer]

# File lib/gdal/raster_attribute_table.rb, line 183
def set_value_as_integer(row, field, value)
  FFI::GDAL::GDAL.GDALRATSetValueAsInt(@c_pointer, row, field, value)
end
Also aliased as: set_value_as_int
set_value_as_string(row, field, value) click to toggle source

@param row [Integer] @param field [Integer] @param value [String]

# File lib/gdal/raster_attribute_table.rb, line 168
def set_value_as_string(row, field, value)
  FFI::GDAL::GDAL.GDALRATSetValueAsString(@c_pointer, row, field, value)
end
to_color_table(entry_count = -1) click to toggle source

@param entry_count [Integer] The number of entries to produce. The default

will try to auto-determine the number.

@return [GDAL::ColorTable, nil]

# File lib/gdal/raster_attribute_table.rb, line 213
def to_color_table(entry_count = -1)
  color_table_pointer = FFI::GDAL::GDAL.GDALRATTranslateToColorTable(@c_pointer, entry_count)
  return if color_table_pointer.nil? || color_table_pointer.null?

  GDAL::ColorTable.new(color_table_pointer)
end
type_of_col(index)
Alias for: column_type
usage_of_col(index)
Alias for: column_usage
value_as_double(row, field) click to toggle source

@param row [Integer] @param field [Integer] @return [Float]

# File lib/gdal/raster_attribute_table.rb, line 160
def value_as_double(row, field)
  FFI::GDAL::GDAL.GDALRATGetValueAsDouble(@c_pointer, row, field)
end
Also aliased as: value_as_float
value_as_float(row, field)
Alias for: value_as_double
value_as_int(row, field)
Alias for: value_as_integer
value_as_integer(row, field) click to toggle source

@param row [Integer] @param field [Integer] @return [Integer]

# File lib/gdal/raster_attribute_table.rb, line 152
def value_as_integer(row, field)
  FFI::GDAL::GDAL.GDALRATGetValueAsInt(@c_pointer, row, field)
end
Also aliased as: value_as_int
value_as_string(row, field) click to toggle source

@param row [Integer] @param field [Integer] @return [String]

# File lib/gdal/raster_attribute_table.rb, line 142
def value_as_string(row, field)
  value_string, ptr = FFI::GDAL::GDAL.GDALRATGetValueAsString(@c_pointer, row, field)
  ptr.autorelease = false

  value_string
end