如何读取 NASA .hgt 二进制文件 [英] how to read NASA .hgt binary files

查看:28
本文介绍了如何读取 NASA .hgt 二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您对二进制文件有所了解,我相信这真的很简单,但我是这方面的新手.

I'm sure this is really simple if you know anything about binary files, but I'm a newbie on that score.

如何从 NASA .hgt 文件中提取数据?这是来自 www2.jpl.nasa.gov/srtm/faq.html 的描述:

How would I extract the data from NASA .hgt files? Here is a description from www2.jpl.nasa.gov/srtm/faq.html:

SRTM 数据文件的名称类似于N34W119.hgt".做什么字母和数字指代,什么是.hgt"格式?

每个数据文件覆盖一个纬度乘以一个经度地球表面的块.前七个字符表示西南街区的一角,其中 N、S、E 和 W 指的是北、南、东,和西部.因此,N34W119.hgt"文件涵盖了北纬 34 到 35 和经度 118-119 西(此文件包括洛杉矶市中心,加利福尼亚).文件扩展名.hgt"仅代表单词高",意为海拔.它不是格式类型.这些文件是以原始"格式(无标题且未压缩),16 位有符号整数,海拔高度以海平面以上米为单位,在地理"(纬度和经度数组)投影,数据空白由 -32768 表示.国际3弧秒文件有1201列1201行数据,总文件大小为 2,884,802 字节 (= 1201 x 1201 x 2).团结的状态 1 角秒文件有 3601 列和 3601 行数据,具有总文件大小为 25,934,402 字节 (= 3601 x 3601 x 2).更多信息阅读文本文件SRTM_Topo.txt"在http://edcftp.cr.usgs.gov/pub/data/srtm/Readme.html

Each data file covers a one-degree-of-latitude by one-degree-of-longitude block of Earth's surface. The first seven characters indicate the southwest corner of the block, with N, S, E, and W referring to north, south, east, and west. Thus, the "N34W119.hgt" file covers latitudes 34 to 35 North and longitudes 118-119 West (this file includes downtown Los Angeles, California). The filename extension ".hgt" simply stands for the word "height", meaning elevation. It is NOT a format type. These files are in "raw" format (no headers and not compressed), 16-bit signed integers, elevation measured in meters above sea level, in a "geographic" (latitude and longitude array) projection, with data voids indicated by -32768. International 3-arc-second files have 1201 columns and 1201 rows of data, with a total filesize of 2,884,802 bytes ( = 1201 x 1201 x 2). United States 1-arc-second files have 3601 columns and 3601 rows of data, with a total filesize of 25,934,402 bytes ( = 3601 x 3601 x 2). For more information read the text file "SRTM_Topo.txt" at http://edcftp.cr.usgs.gov/pub/data/srtm/Readme.html

感谢您的帮助!我将在 python 脚本中使用这些数据,所以如果你不能对任何其他语言使用任何特定于语言的技巧,那就太棒了.

Thanks for any help! I am going to use this data in a python script, so if you could not use any language-specific tricks for any other languages, that would be awesome.

推荐答案

一个经过测试的numpy示例:

A tested numpy example:

import os
import math
import numpy

fn = 'DMV/N51E000.hgt'

siz = os.path.getsize(fn)
dim = int(math.sqrt(siz/2))

assert dim*dim*2 == siz, 'Invalid file size'

data = numpy.fromfile(fn, numpy.dtype('>i2'), dim*dim).reshape((dim, dim))

这篇关于如何读取 NASA .hgt 二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆