[Gdal-dev] gdal java bindings

Christopher Condit condit at sdsc.edu
Mon Jul 31 13:26:11 EDT 2006


OK - I got it.  I was concerned about the -128 to 127 value range, and I
realized that Java is problematic because it lacks unsigned types. So in
the case of "Byte" types, the code should actually look like this:
int actualValue = 0xFF & data.get(); //where data is your ByteBuffer

In the event of wider data types, you'll have to do the above
calculation and then bitwise or the results together in the proper byte
order.

-Chris

-----Original Message-----
From: Collins, Benjamin [mailto:collinsb at mitre.org] 
Sent: Friday, July 28, 2006 7:43 AM
To: Christopher Condit; gdal-dev
Subject: RE: [Gdal-dev] gdal java bindings

>-----Original Message-----
>From: gdal-dev-bounces at lists.maptools.org 
>[mailto:gdal-dev-bounces at lists.maptools.org] On Behalf Of 
>Christopher Condit
>Sent: Thursday, July 27, 2006 6:57 PM
>To: gdal-dev
>Subject: [Gdal-dev] gdal java bindings
>
>Does anyone have experience with the GDAL Java bindings?  I'm trying
to
>use them for raster access and can't seem to get the raw data.
>
>The key problem seems to me that band.GetOffset, GetScale, and
>GetNoDataValue are failing. They all return void in the Double[]. Am I
>calling them wrong? getXSize/getYsize works fine.
>

A few notes...

Unless you are sure that your data is in byte format, the buffer
allocation of "x * y" is a bad idea as it may under-allocate if your
data has more than one byte per pixel.  Use something like: 
(x * y) * (gdal.GetDataTypeSize(band.getDataType()) / 8);

I looked into the GDAL Docs, and it seems that it is not guaranteed
that scale and offset are going to be set.  In that case, they could be
null or undefined.  Also, you could make sure that you are getting the
number of pixels you expect, and are executing that loop once for each
pixel.  Other than that, I have always had success getting data from
RasterIO.

Sorry I could not help more...feel free to send me the test file that
you were using.
--
Ben





More information about the Gdal-dev mailing list