[gdal-dev] DTED Elevations with Java and gdal

Corrado, George P. George.Corrado at gd-ais.com
Wed Oct 20 15:03:12 EDT 2010


Hey Even,

So I was messing around with one of the gdal examples that prints a lot of debug info, which is nice.  I found a thread where someone wanted to get elevation data at a certain point or pixel.  I think it was Frank who responded to it.  Anyway, I tried to follow along, and I think I'm in the right place in code.  I've got the dted file loaded, it has gone through this line without error:

returnVal = poBand.ReadRaster_Direct(0, 0, poBand.getXSize(), poBand.getYSize(), xsize, ysize, buf_type, data.slice());


and this bit of code:

short[][] shorts = new short[bandCount][];
            for (int i = 0; i < bandCount; i++)
            {
                shorts[i] = new short[pixels];
                bands[i].asShortBuffer().get(shorts[i]);
            }
            imgBuffer = new DataBufferShort(shorts, pixels);
            buffer_type = DataBuffer.TYPE_USHORT;
            sampleModel = new BandedSampleModel(buffer_type,
                    xsize, ysize, xsize, banks, offsets);
            data_type = BufferedImage.TYPE_USHORT_GRAY;


does the imgBuffer or the sampleModel contain any elevation data for a given point?  Or do I have to get it from the Band class higher up in the code?  I think it would be cool to get all the pixel elevation data and then color each pixel according to elevation height.

I think this is the example I was working with:
http://trac.osgeo.org/gdal/browser/trunk/gdal/swig/java/apps/GDALtest.java

I saw this piece of code when I was browsing around the threads, but wasn't sure what geo_x and geo_y should be or where they come from.

double[] test = poDataset.GetGeoTransform();
        double pixel_x = (geo_x - test[0]) / test[1];
        double pixel_y = (geo_y - test[3]) / test[5];


Sorry for all the questions and pasting code.
Thanks,
George
-----Original Message-----
From: Even Rouault [mailto:even.rouault at mines-paris.org] 
Sent: Tuesday, October 19, 2010 2:04 PM
To: gdal-dev at lists.osgeo.org
Cc: Corrado, George P.
Subject: Re: [gdal-dev] DTED Elevations with Java and gdal

George,

It's not appropriate to convert from DTED to PNG. See the warning of 
gdal_translate : DTED is signed 16 bits, but PNG can only support unsigned 16 
bits. So if you translate from DTED to PNG you'll lose the negative values 
(and in particular the nodata=-32767). I'm not sure why you want to convert 
your DTED file and not use it directly ? If you really don't want to read the 
DTED, convert to Geotiff instead

To do this with Java, see the Driver.CreateCopy() method :

http://gdal.org/java/org/gdal/gdal/Driver.html#CreateCopy(java.lang.String,
%20org.gdal.gdal.Dataset)

Best regards,

Even

Le mardi 19 octobre 2010 19:33:53, Corrado, George P. a écrit :
> Hello,
> 
> Does anyone have a java example on how to get elevations from a .dt1 file. 
> My ultimate goal would be to take a .dt1, translate it to a png, and then
> feed the png into gdal to get elevations and coordinates.
> 
> I ran the gdal_translate on one of my .dt1 files and came up with this. 
> Note: this is actually DTED2 even though the file ext is dt1.  Not sure
> why that is, maybe because it's really old.
> 
> C:\jdk1.6.0_21\bin>gdal_translate -of PNG --config GDAL_CACHEMAX 30
> C:\DTED2\DTED\E032\N34.DT1 C:\DTED2\DTED\E032\N34.pn g
> Input file size is 3601, 3601
> Warning 6: PNG driver doesn't support data type Int16. Only eight bit
> (Byte) and sixteen bit (UInt16) bands supported. D efaulting to Byte
> 
> 0...10...20...30...40...50...60...70...80...90...100 - done.
> 
> It created a png file along with an xml file.  I had to do this with the
> gdal_translate.exe file, but eventually I would like to use straight Java.
> 
> Thanks,
> George


More information about the gdal-dev mailing list