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 ? – gansub Nov 8 '14 at 11:07
2

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.

  • 1
    Very nice WhiteboxDev ! Sometimes I feel like I must ask an SRTM question just to learn more from you ! – gansub Nov 9 '14 at 7:00
  • 1
    @user311554 Ha! I'm glad to help. – WhiteboxDev Nov 9 '14 at 13:06
  • 1
    It almost seems as if Whitebox GAT can do everything a GIS software can do and more! – Joseph Nov 10 '14 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.