java - Java 中的 Nasa 二进制文件

标签 java file-io binary

我有包含二进制数据的文件。这是规范:

The SRTM data files have names like "N34W119.hgt". What do the letters and numbers refer to, and what is ".hgt" format?

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

谁能帮我如何用java读取这个文件?可以将此文件读取到数组中,因为我需要对此文件中的元素执行一些操作?

最佳答案

我会将整个文件读入 ShortBuffer(因此您可以选择字节序)

FileChannel fc = new FileInputStream(file).getChannel();
ByteBuffer bb = ByteBuffer.allocateDirect((int) fc.size());
while (bb.remaining() > 0) fc.read(bb);
fc.close();
bb.flip();
// choose the right endianness
ShortBuffer sb = bb.order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();

关于java - Java 中的 Nasa 二进制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8194447/

相关文章:

c++ - 无法在 OpenCV 中打开 1 位二进制图像?

java - 在 OpenCV 3.2 中返回 Java 中的 Mat 对象

java - 所有收集器的Hadoop初始化失败。最后一个收集器的错误是:null

javascript - 使用 Javascript 格式化纯文本的最快方法

java - 使用java在连接到Lan的其他电脑上创建文件

java - 如何使用 Apache Avro 对 JSON 字符串进行 Avro 二进制编码?

java - 如何终止长时间运行的报告

java - 使用证书的 SSL 连接

java - 如何为 SimpleFileVisitor 类实现 JProgressbar

file - 在Delphi中的二进制文件中间插入记录