-
Notifications
You must be signed in to change notification settings - Fork 1
/
04_make_vrts_from_tiles.py
59 lines (46 loc) · 1.46 KB
/
04_make_vrts_from_tiles.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: utf-8 -*-
"""
Created on Mon Apr 17 17:33:11 2017
@author: braatenj
"""
import os
import sys
import fnmatch
import subprocess
arg = sys.argv
searchDir = arg[1]
vrtFile = arg[2]
search = arg[3]
#searchDir = '/vol/v2/conus_tiles/tiles_topo/'
#vrtFile = '/vol/v2/conus_tiles/vrts/ned_dem_ee_conus_20170501_elevation.vrt'
#search = '*ned_dem_ee_conus_20170501_elevation.bsq'
if searchDir[-1] != '/':
searchDir += '/'
bsqs = []
for root, dirnames, filenames in os.walk(searchDir):
for filename in fnmatch.filter(filenames, search):
bsqs.append(os.path.join(root, filename))
# check to make sure that total number of tiles and the tiles sizes are correct
nbsqs = len(bsqs)
if nbsqs != 2319:
print('Warning - there are not 2319 bsq files in the provided directory')
print(' ...there are '+str(nbsqs))
raise SystemExit
fileSize = [os.path.getsize(bsq) for bsq in bsqs]
if (len(set(fileSize)) > 1):
print('Warning - all of the files are not the same size')
print(' ...there are possibly incomplete files')
raise SystemExit
else:
print('Everything checks out!')
print(' ...making VRT file')
# make a list of tile bsqs
tileListFile = vrtFile.replace('.vrt', '_filelist.txt')
tileList = open(tileListFile, 'w')
for bsq in bsqs:
tileList.write(bsq+'\n')
tileList.close()
# create vrt
cmd = 'gdalbuildvrt -vrtnodata -9999 -hidenodata -input_file_list '+tileListFile+' '+vrtFile
subprocess.call(cmd, shell=True)
#os.remove(tileListFile)