SRTM数据处理(使用Python语言)
背景
笔者在做GIS相关研究的期间,需要从SRTM数据中提取高程值(数据后缀为.hgt),在经过漫长的网络检索过程后,从https://librenepal.com/article/reading-srtm-data-with-python/处获取到灵感,略微修改,得到下面的代码,希望可以帮助到大家。代码的主要功能是:通过入参传入点的经度和纬度,自动寻找.hgt文件的路径,并通过路径提取该点的高程值。
import os
import json
import numpy as np
SAMPLES = 1201 # Change this to 3601 for SRTM1
# HGTDIR = 'hgt' # All 'hgt' files will be kept here uncompressed
def get_elevation(lon, lat):
hgt_file = get_file_name(lon, lat)
if hgt_file:
return read_elevation_from_file(hgt_file, lon, lat)
# Treat it as data void as in SRTM documentation
# if file is absent
return -32768
def read_elevation_from_file(hgt_file, lon, lat):
with open(hgt_file, 'rb') as hgt_data:
# HGT is 16bit signed integer(i2) - big endian(>)
elevati