How do I access .HGT SRTM files in C++?

限于喜欢 提交于 2019-12-30 10:54:07

问题


Here is a similar question on the topic with a good description of the file:

how to read NASA .hgt binary files

I am fairly new to programming in general and my efforts thus far have been very limited. My ultimate goal is to access the elevation data and store it in a 2D array for easy access. I have been trying to read the file 2 bytes at a time, as has been suggested, but I don't know what to do next. Here is what I've got so far:

    #include <iostream>
    #include <fstream>

    using namespace std;

    int main () 
    {
        ifstream::pos_type size;
        char * memblock;

        ifstream file ("N34W119.hgt", ios::in|ios::binary|ios::ate);

        if (file.is_open())
        {
            size = 2; 
            memblock = new char [size];

            file.seekg (0, ios::beg);

            file.read (memblock, size);

            //I don't know what to do next




            file.close();
        }
        return 0;
    }

Thanks for any help!


回答1:


// SRTM_version 1201 or 3601 
int height[SRTM_version][SRTM_version]; 
for ( int r = 0; r < SRTM_version ; r++ ) {
   for ( int c = 0 ; c < SRTM_verision; c++ ) {
      height[r][c] = (memblock[0] << 8) | memblock[1];  
   }
}


来源:https://stackoverflow.com/questions/13810178/how-do-i-access-hgt-srtm-files-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!