how to read NASA .hgt binary files

后端 未结 6 962
你的背包
你的背包 2020-12-07 19:26

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

How would I extract the data from NASA .hgt files? Here is

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 19:38

    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))
    

提交回复
热议问题