-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathconvert_to_bt.py
More file actions
35 lines (27 loc) · 1.17 KB
/
Copy pathconvert_to_bt.py
File metadata and controls
35 lines (27 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# -*- coding: utf-8 -*-
import os
import subprocess
''' Convert to Binary Terrain files '''
def convert_to_bt(input_path, output_path):
if not os.path.exists(output_path):
os.mkdir(output_path)
for file in os.listdir(input_path):
input_file = os.path.join(input_path, file)
if os.path.isfile(input_file):
file_name = file.split(".")
if file_name[1] == input_raster_extension:
output_file = os.path.join(output_path, file_name[0] + ".bt")
gdal_command = "gdal_translate -of bt {} {}".format(input_file, output_file)
process = subprocess.Popen(gdal_command).communicate()[0]
''' Generate tileindex '''
def generate_raster_tileindex(path):
tileindex_file = os.path.join(path, "tileindex.shp")
gdal_command = "gdaltindex {} {}".format(tileindex_file, os.path.join(path, "*.bt"))
output = subprocess.Popen(gdal_command).communicate()[0]
# Define variables
input_path = os.path.normpath(r"C:\Temp")
output_path = os.path.join(input_path, "output")
input_raster_extension = "asc"
# Execute scripts
convert_to_bt(input_path, output_path)
generate_raster_tileindex(output_path)