[gdal-dev] GDAL DataType class

Pinner, Luke Luke.Pinner at environment.gov.au
Wed Oct 28 19:20:44 EDT 2009


You could easily roll your own.

from osgeo import gdal

class GdalDataType(object):

    def __init__(self, nbits, Float, Complex):

        for i in range(0,gdal.GDT_TypeCount):
            self.DataType=None
            DataType=i
            DataTypeName=gdal.GetDataTypeName(i)
            DataTypeSize=gdal.GetDataTypeSize(i)
            DataTypeIsFloat ='Float' in DataTypeName
            DataTypeIsComplex=gdal.DataTypeIsComplex(i)==1

            if DataTypeSize==nbits and DataTypeIsFloat==Float and
DataTypeIsComplex==Complex:
                self.DataType=DataType
                self.DataTypeName=DataTypeName
                self.DataTypeSize=DataTypeSize
                self.DataTypeIsFloat=DataTypeIsFloat
                self.DataTypeIsComplex=DataTypeIsComplex
                break
        if self.DataType is None: raise TypeError, 'No matching DataType
found'

gdt=GdalDataType(nbits=32, Float=True, Complex=False)
print gdt.DataTypeName

Luke

-----Original Message-----
From: gdal-dev-bounces at lists.osgeo.org
[mailto:gdal-dev-bounces at lists.osgeo.org] On Behalf Of Luca Fasano
Sent: Thursday, 29 October 2009 3:19 AM
To: gdal-dev at lists.osgeo.org
Subject: [gdal-dev] GDAL DataType class

Hi all,
I need a way to retrieve a GDAL DataType (its code or its string name,
it's the same) starting from all information on it. Does it exist a
class or method to to this?
For example:
GdalDataType(nbits=32, float=True, Complex=True) -> gdal.GDT_CFloat32
I use Python bindings for GDAL.

I'd like to avoid building the string manually (i.e.
'GDT_'+'C'+'Float'+'32')
Thanks 

_______________________________________________
gdal-dev mailing list
gdal-dev at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev


------
If you have received this transmission in error please notify us immediately by return e-mail and delete all copies. If this e-mail or any attachments have been sent to you in error, that error does not constitute waiver of any confidentiality, privilege or copyright in respect of information in the e-mail or attachments. 



Please consider the environment before printing this email.

------



More information about the gdal-dev mailing list