MCPcopy Create free account
hub / github.com/comaps/comaps / main

Function main

tools/python/tif2hgt.py:6–35  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4import zipfile
5
6def main():
7 if len(sys.argv) != 4:
8 print("Usage: tif2hgt.py <src aster path> <tmp path> <dest srtm path>")
9 return
10
11 aster_path = str(sys.argv[1])
12 tmp_path = str(sys.argv[2])
13 srtm_path = str(sys.argv[3])
14
15 for file in os.listdir(aster_path):
16 if file.endswith(".zip"):
17 dest_dir = tmp_path + '/' + file
18 with zipfile.ZipFile(aster_path + '/' + file, 'r') as zip_ref:
19 os.mkdir(dest_dir)
20 zip_ref.extractall(dest_dir)
21
22 for tif_file in os.listdir(dest_dir):
23 # Sample: ASTGTMV003_N61E010_dem.tif
24 if tif_file.endswith("dem.tif"):
25 print("Process: " + tif_file[11:18])
26
27 arch_name = tif_file[11:18] + '.SRTMGL1.hgt'
28 out_file = srtm_path + '/' + arch_name
29 os.system('gdal_translate -of SRTMHGT ' + dest_dir + '/' + tif_file + ' ' + out_file)
30
31 zipfile.ZipFile(out_file + '.zip', mode='w', compression=zipfile.ZIP_DEFLATED).write(out_file, arch_name)
32
33 os.remove(out_file)
34 shutil.rmtree(dest_dir)
35 break
36
37main()

Callers 1

tif2hgt.pyFile · 0.70

Calls 2

writeMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected