[gdal-dev] Setting DataType in ReadAsArray
Chris Barker
chris.barker at noaa.gov
Tue Oct 16 14:55:45 PDT 2012
On Tue, Oct 16, 2012 at 1:59 PM, Antonio Falciano <afalciano at yahoo.it> wrote:
>> Does anybody know of a way to set the data type in the call ReadAsArray.
>> It is currently reading a field as an unsigned int and it needs to be read
>> as a signed int.
> ReadAsArray returns substantially a numpy array, so you can use np
> functions and methods of conversions between data types [1]. Finally,
> the simplest way consists into using the .astype() method. Hope this helps!
Actually you probably don't want that -- .astype() does a type
conversion, and what you want is to interpret the data in a different
way -- you can use .view for that -- somethign like:
arr =... ReadAsArray(...)
arr2 = arr.view(dtype=np.int32) # or the appropriate type.
that will create a new array that points to the same data buffer, but
interpretting the buffer as the new type
though I'd think ReadAsArray would get it right....
-Chris
> Cheers,
> Antonio
>
> [1] http://docs.scipy.org/doc/numpy/user/basics.types.html
>
> --
> Antonio Falciano
> http://www.linkedin.com/in/antoniofalciano
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
--
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