Class: GdalStuff

Inherits:
Object
  • Object
show all
Defined in:
lib/gdal_helper.rb

Overview

class with constants and bits that will be used by all gdal-helper classes

Direct Known Subclasses

GdalBand, GdalFile

Instance Method Summary collapse

Instance Method Details

#data_type_from_gdal(data_type) ⇒ Object

Does type mappings from gdal to ruby - pretty basic, and needs to be expanded so other types can be done, like for example 32 bit integer types, 16 bit types, double floating bit types, unsigned int types, etc..



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/gdal_helper.rb', line 50

def data_type_from_gdal(data_type)
  case (data_type)
    when Gdal::Gdalconst::GDT_UNKNOWN; return null
    when Gdal::Gdalconst::GDT_BYTE; return String
    when Gdal::Gdalconst::GDT_UINT16 ; return Integer
    when Gdal::Gdalconst::GDT_INT16; return Integer
    when Gdal::Gdalconst::GDT_UINT32; return Integer
    when Gdal::Gdalconst::GDT_INT32; return Integer
    when Gdal::Gdalconst::GDT_FLOAT32; return Float
    when Gdal::Gdalconst::GDT_FLOAT64; return Float
    when Gdal::Gdalconst::GDT_CINT16; return Integer
    when Gdal::Gdalconst::GDT_CINT32; return Float
    when Gdal::Gdalconst::GDT_CFLOAT32; return Float
    when Gdal::Gdalconst::GDT_CFLOAT64; return Float
    else raise ArgumentError("Unknown data type.. not sure what to do here folks", caller)
  end
end

#data_type_to_gdal(data_type) ⇒ Object

Does type mappings from ruby to gdal - pretty basic, and needs to be expanded so other types can be done, like for example 32 bit integer types, 16 bit types, double floating bit types, unsigned int types, etc..

Raises:

  • (ArgumentError)


70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/gdal_helper.rb', line 70

def data_type_to_gdal ( data_type )
  #puts("DEBUG: data_type_to_gdal(#{data_type})")
  # Does not work, something is wrong with my understanding of the case statement and class compares..
  #case (data_type)
  #  when String; return Gdal::Gdalconst::GDT_BYTE
  #  when Integer; return Gdal::Gdalconst::GDT_INT16
  #  when Float; return Gdal::Gdalconst::GDT_FLOAT32
  #end
  return Gdal::Gdalconst::GDT_BYTE if (data_type == String )
  return Gdal::Gdalconst::GDT_INT16 if (data_type == Integer )
  return Gdal::Gdalconst::GDT_FLOAT32 if (data_type == Float )
  raise ArgumentError, "#{data_type} is not a valid (String|Integer|Float) data type.. not sure what to do here folks", caller
end