GDAL DataType class

5 messages Options
Embed this post
Permalink
LFas

GDAL DataType class

Reply Threaded More More options
Print post
Permalink
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
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Frank Warmerdam

Re: GDAL DataType class

Reply Threaded More More options
Print post
Permalink
Luca Fasano wrote:

> 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

Luca,

No such function exists.

Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, [hidden email]
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent

_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Howard Butler

Re: GDAL DataType class

Reply Threaded More More options
Print post
Permalink

On Oct 28, 2009, at 11:35 AM, Frank Warmerdam wrote:

> Luca Fasano wrote:
>> 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
>
> Luca,
>
> No such function exists.

We could take a patch and apply it to the Python bindings if you were  
to provide it though.  That would be handy, especially if it were  
smart enough to throw exceptions for permutations that can't exist in  
GDAL.

Howard
_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Pinner, Luke

RE: GDAL DataType class

Reply Threaded More More options
Print post
Permalink
In reply to this post by LFas
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: [hidden email]
[mailto:[hidden email]] On Behalf Of Luca Fasano
Sent: Thursday, 29 October 2009 3:19 AM
To: [hidden email]
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
[hidden email]
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.

------

_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Pinner, Luke

RE: GDAL DataType class

Reply Threaded More More options
Print post
Permalink
Ooops... I neglected the signed check.

from osgeo import gdal

class GdalDataType(object):

    def __init__(self, nbits, Float, Signed=True, Complex=False):

        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
            DataTypeIsSigned = DataTypeIsFloat or DataTypeName[0:4] in
['Byte','UInt']
            DataTypeIsComplex=gdal.DataTypeIsComplex(i)==1

            if DataTypeSize==nbits and DataTypeIsFloat==Float and
DataTypeIsSigned==Signed and DataTypeIsComplex==Complex:
                self.DataType=DataType
                self.DataTypeName=DataTypeName
                self.DataTypeSize=DataTypeSize
                self.DataTypeIsFloat=DataTypeIsFloat
                self.DataTypeIsSigned=DataTypeIsSigned
                self.DataTypeIsComplex=DataTypeIsComplex
                if DataTypeIsSigned:
                    self.DataTypeRange=[-2**(nbits-1),2**(nbits-1)]
                else:
                    self.DataTypeRange=[0,2**nbits-1]
                break
        if self.DataType is None: raise TypeError, 'No matching DataType
found'

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

-----Original Message-----
From: Pinner, Luke
Sent: Thursday, 29 October 2009 10:21 AM
To: 'Luca Fasano'; [hidden email]
Subject: RE: [gdal-dev] GDAL DataType class

You could easily roll your own.

from osgeo import gdal

class GdalDataType(object):

    def __init__(self, nbits, Float, Complex=False, Signed=False):

        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: [hidden email]
[mailto:[hidden email]] On Behalf Of Luca Fasano
Sent: Thursday, 29 October 2009 3:19 AM
To: [hidden email]
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
[hidden email]
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.

------

_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev