Repo created
This commit is contained in:
parent
4af19165ec
commit
68073add76
12458 changed files with 12350765 additions and 2 deletions
37
tools/python/tif2hgt.py
Normal file
37
tools/python/tif2hgt.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import sys
|
||||
import os
|
||||
import shutil
|
||||
import zipfile
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 4:
|
||||
print("Usage: tif2hgt.py <src aster path> <tmp path> <dest srtm path>")
|
||||
return
|
||||
|
||||
aster_path = str(sys.argv[1])
|
||||
tmp_path = str(sys.argv[2])
|
||||
srtm_path = str(sys.argv[3])
|
||||
|
||||
for file in os.listdir(aster_path):
|
||||
if file.endswith(".zip"):
|
||||
dest_dir = tmp_path + '/' + file
|
||||
with zipfile.ZipFile(aster_path + '/' + file, 'r') as zip_ref:
|
||||
os.mkdir(dest_dir)
|
||||
zip_ref.extractall(dest_dir)
|
||||
|
||||
for tif_file in os.listdir(dest_dir):
|
||||
# Sample: ASTGTMV003_N61E010_dem.tif
|
||||
if tif_file.endswith("dem.tif"):
|
||||
print("Process: " + tif_file[11:18])
|
||||
|
||||
arch_name = tif_file[11:18] + '.SRTMGL1.hgt'
|
||||
out_file = srtm_path + '/' + arch_name
|
||||
os.system('gdal_translate -of SRTMHGT ' + dest_dir + '/' + tif_file + ' ' + out_file)
|
||||
|
||||
zipfile.ZipFile(out_file + '.zip', mode='w', compression=zipfile.ZIP_DEFLATED).write(out_file, arch_name)
|
||||
|
||||
os.remove(out_file)
|
||||
shutil.rmtree(dest_dir)
|
||||
break
|
||||
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue