[Gdal-dev] gdal java bindings

Christopher Condit condit at sdsc.edu
Fri Jul 28 06:52:05 EDT 2006


Hi Daniele-

No, I'm not sure that it does. But here's the thing that bugs me: when I
run my Java code it concludes that

Min=-128

Max = 127

 

However, when I run gdalinfo on the file, I get the following
information:

 

Driver: JPEG/JPEG JFIF

Size is 2592, 1296

Band 1 Block=2592x1 Type=Byte, ColorInterp=Red

    Computed Min/Max=0.000,235.000

Band 2 Block=2592x1 Type=Byte, ColorInterp=Green

    Computed Min/Max=0.000,228.000

Band 3 Block=2592x1 Type=Byte, ColorInterp=Blue

    Computed Min/Max=0.000,238.000

 

So I thought I might be reading the ByteBuffer incorrectly.

 

Thanks,

 

Chris

 

________________________________

From: Daniele Romagnoli [mailto:dany.geotools at gmail.com] 
Sent: Friday, July 28, 2006 1:36 AM
To: Christopher Condit
Subject: Re: [Gdal-dev] gdal java bindings

 

Hi Cris.

Are you sure that the rasterBand of your sample file contains the Offset
and Scale values?
They are optional properties of a RasterBand. 

I have used your code with my HDF format samples and it works fine. 

Maybe your sample has no information about this.

regards, Daniele

On 7/28/06, Christopher Condit <condit at sdsc.edu > wrote:

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. 

Here's the function:
void dump()
        {
                Band band = image.GetRasterBand(1);
                int x = band.getXSize();
                int y = band.getYSize();
                ByteBuffer data = ByteBuffer.allocateDirect(x * y);

                band.ReadRaster_Direct(0, 0, x, y, x, y,
band.getDataType(), data);
                Double[] offset = new Double[1], scale = new Double[1],
nodata = new Double[1]; 
                band.GetOffset(offset);
                band.GetScale(scale);
                band.GetNoDataValue(nodata);
                double min = 1000;
                double max = -1000;
                while ( data.hasRemaining())
                {
                        double val = (data.get() * scale[0]) +
offset[0];
                        if (val < min)
                                min = val;
                        if (val > max) 
                                max = val;
                }
                System.out.println(min + " " + max);
        }

Thanks,

Chris

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

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20060728/1a2a9d89/attachment.html


More information about the Gdal-dev mailing list