2

I have read the following posts on reading in SRTM HGT elevations- How do you convert SRTM HGT elevations from WGS84 into meters above sea level? and How to extract elevation from .HGT file? I am currently undertaking this exercise using Java on an Intel Platform. My machine "endianness" is actually little endian and so when I write this file out differently(south to north as a meteorological application requires it that way) are there any additional steps to be carried out ? My initial code checked on the endianness of the system and then read in the .hgt file appropriately. When I actually ran the weather simulation I got strange elevation values.

        fc = new FileInputStream(file).getChannel();
        ByteBuffer bb = ByteBuffer.allocateDirect((int) fc.size());
        while (bb.hasRemaining()) fc.read(bb);
        bb.flip();
        sb = bb.order(ByteOrder.BIG_ENDIAN).asShortBuffer();
  • Java algorithm to fix this - 1) Read in as Big Endian into a Short Buffer and 2) Write it out to the disk by querying the actual endianness. Comments ? –  Nov 08 '14 at 11:07

1 Answers1

1

The following is the Java source code for the Import SRTM tool in the open-source GIS Whitebox GAT, for which I am a developer. You can use it as an example for how to convert the endianness of the data to that of the system.

https://code.google.com/p/whitebox-geospatial-analysis-tools/source/browse/trunk/ImportExport/src/plugins/ImportSRTM.java

Feel free to use the code as is or to modify it as you see fit. The code is well tested and I am confident that it works well with both SRTM-1 and SRTM-3 data. It writes the output to the Whitebox raster format (WhiteboxRaster and WhiteboxRasterBase classes), which has the endianness of whatever system is used to create the file.

WhiteboxDev
  • 11,025
  • 1
  • 35
  • 65