[Gdal-dev] int64 support?

Christopher Barker Chris.Barker at noaa.gov
Fri Aug 10 12:26:55 EDT 2007


Vincent Schut wrote:
> Not really necessary, but it would be convenient if gdal supported
> (u)int64 data... Using numpy on my amd64 linux pc, when I create a numpy
> array without specifying the datatype it defaults to int64, which gdal
> refuses to save. Usually an 'astype(int32)' suffices, but still it is a
> bit annoying sometimes.

hmm this isn't a very compelling argument to me.

The question is: Do you have a need to create/read (u)int64 data?

If there is a need for that, then it may be worth supporting, but if 
it's only about the defaults of numpy -- that should be addressed 
elsewhere: either in your code or in numpy itself, which brings me to:

 > Using numpy on my amd64 linux pc, when I create a numpy
 > array without specifying the datatype it defaults to int64.

First, that's int64, not uint64 -- is there any need for uint64?

Second -- how are you creating your arrays? Many of the array 
constructors default to float64 now. However, what I suspect is that you 
are creating arrays from python integers, in which case numpy will (or 
should!) default to the same datatype as a python integer, which is 
apparently int64 on amd64 Linux.

Anyway, it's always a good practice to specify the data type when 
creating an array that's going to interact with any outside package. The 
numpy developers have made a substantial effort to keep accidental 
upcasts from happening with operations with python numbers:

 >>> import numpy as N
 >>> a = N.ones((3,3), dtype=N.int16)
 >>> a.dtype
dtype('int16')
 >>> b = a * 5
 >>> b.dtype
dtype('int16')

(I'm on a 32bit machine, so I used int16 as my example)

So you should be OK if you create them as int32 to start with.

When writing a function that requires a particular data type, it's very 
handy to start it out with something like:

def CreateGDALSomething(InputArray):
     InputArray = N.asarray(InputArray, dtype=N.int32)
     ...
     ...

asarray() will be a no-op if the input array is already the right type.

As a rule, whenever you are creating GDAL object, you should know what 
kind of file you're creating, and that includes the datatype.

In short -- if you follow numpy and GDAL best practices you shouldn't 
have a problem.

-Chris


-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov



More information about the Gdal-dev mailing list