Class: GdalBand

Inherits:
GdalStuff show all
Defined in:
lib/gdal_helper.rb

Overview

Class wrapping up a gdal band.

Instance Method Summary collapse

Methods inherited from GdalStuff

#data_type_from_gdal, #data_type_to_gdal

Constructor Details

#initialize(band) ⇒ GdalBand

Returns a new instance of GdalBand.



90
91
92
# File 'lib/gdal_helper.rb', line 90

def initialize( band)
  @band = band
end

Instance Method Details

#data_typeObject

returns the datatype



104
105
106
# File 'lib/gdal_helper.rb', line 104

def data_type()
  data_type_from_gdal(@band.DataType)
end

#data_type_prettyObject

returns the datatype as a string in a gdal like manner



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/gdal_helper.rb', line 109

def data_type_pretty()
  type_string = case(@band.DataType)
    when Gdal::Gdalconst::GDT_UNKNOWN; 'GDT_UNKNOWN'
    when Gdal::Gdalconst::GDT_BYTE; 'GDT_BYTE'
    when Gdal::Gdalconst::GDT_UINT16;'GDT_UINT16'
    when Gdal::Gdalconst::GDT_INT16;'GDT_INT16'
    when Gdal::Gdalconst::GDT_UINT32; 'GDT_UINT32'
    when Gdal::Gdalconst::GDT_INT32; 'GDT_INT32'
    when Gdal::Gdalconst::GDT_FLOAT32; 'IDT_FLOAT32'
    when Gdal::Gdalconst::GDT_FLOAT64; 'GDT_FLOAT64'
    when Gdal::Gdalconst::GDT_CINT16; 'GDT_CINT16'   
    when Gdal::Gdalconst::GDT_CINT32; 'GDT_CINT32'  
    when Gdal::Gdalconst::GDT_CFLOAT32; 'GDT_CFLOAT32' 
    when Gdal::Gdalconst::GDT_CFLOAT64; 'GDT_CFLOAT64'
    else raise ArgumentError("Unknown data type.. not sure what to do here folks", caller)
  end
  type_string
end

#read(start_x, start_y, width_x, width_y) ⇒ Object

Reads data



94
95
96
# File 'lib/gdal_helper.rb', line 94

def read(start_x, start_y, width_x, width_y)
  return unpack(width_y*width_x,  @band.read_raster(start_x,start_y,width_x,width_y))
end

#to_sObject

converts to a string for display/print/other .to_s action



129
130
131
# File 'lib/gdal_helper.rb', line 129

def to_s
  "#{data_type_pretty}"
end

#write(start_x, start_y, width_x, width_y, data) ⇒ Object

Writes data



99
100
101
# File 'lib/gdal_helper.rb', line 99

def write(start_x, start_y, width_x, width_y, data)
  return @band.write_raster(start_x,start_y,width_x,width_y, pack(data))
end