HGT 파일에 저장된 고도 데이터를 읽으려고합니다. 내가 아는 한 이진 파일로 읽을 수 있습니다.C++에서 HGT 파일을 읽는 방법
내가이 스레드 발견 : 해당 게시물을 바탕으로
How do I access .HGT SRTM files in C++?
, 내 예제 코드는 다음과 같습니다 처음 실행 후
#include <iostream>
#include <fstream>
int main(int argc, const char * argv[])
{
std::ifstream::pos_type size;
char * memblock;
std::ifstream file ("N45W066.hgt", std::ios::in|std::ios::binary|std::ios::ate);
if (file.is_open())
{
size = 2;
memblock = new char [size];
file.seekg(0, std::ios::beg);
file.read(memblock, size);
int srtm_ver = 1201;
int height[1201][1021];
for (int i = 0; i<srtm_ver; ++i){
for (int j = 0; j < srtm_ver; ++j) {
height[i][j] = (memblock[0] << 8 | memblock[1]);
std::cout<<height[i][j]<<" ";
}
std::cout<<std::endl;
}
}
return 0;
}
를, 그것은 나에게 제로의 무리, 아무것도를 제공합니다 else : | hgt 파일은 훌륭합니다. 여러 유형의 맵 파일을 읽을 수있는 응용 프로그램과 함께 테스트했으며, 필요한 높이 데이터가 들어 있습니다.
총 파일에서 2 바이트 만 읽는 중입니다. 배열의 각 위치에 대해 2 바이트를 읽어야합니다. 또한 배열 크기의 두 번째 차원에 오타가 있습니다. –
나는 똑같은 것을 짐작하고 있었지만 전체 파일을 읽는 방법을 알려 주실 수 있습니까? 또는 특정 라인/픽셀 위치를 읽는 방법? –