-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRaster180to360.py
More file actions
60 lines (56 loc) · 1.84 KB
/
Copy pathRaster180to360.py
File metadata and controls
60 lines (56 loc) · 1.84 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import os
import subprocess
import sys
inFile = sys.argv[1]
gdal_translateFile = r"C:\OSGeo4W64\bin\gdal_translate.exe"
gdal_warpFile = r"C:\OSGeo4W64\bin\gdalwarp.exe"
# function that sends command to console
def check_output(command,console):
if console == True:
process = subprocess.Popen(command)
else:
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
output,error = process.communicate()
returncode = process.poll()
return returncode,output
# process raster
part1 = inFile.split(os.extsep)[0] + "_pt1.tif"
part2 = inFile.split(os.extsep)[0] + "_pt2.tif"
outFile = inFile.split(os.extsep)[0] + "_360.tif"
if not os.path.exists(outFile):
# clip part 1
args = []
args.append('"'+gdal_translateFile+'"')
args.append('-projwin -180 90 0 -90')
args.append('-a_ullr 180 90 360 -90')
args.append('"'+inFile+'"')
args.append('"'+part1+'"')
command = " ".join(args)
print command
returncode,output = check_output(command, True)
print output
# clip part 2
args = []
args.append('"'+gdal_translateFile+'"')
args.append('-projwin 0 90 180 -90')
args.append('-a_ullr 0 90 180 -90')
args.append('"'+inFile+'"')
args.append('"'+part2+'"')
command = " ".join(args)
print command
returncode,output = check_output(command, True)
print output
# merge 2 parts together
args = []
args.append('"'+gdal_warpFile+'"')
args.append('"'+part1+'"')
args.append('"'+part2+'"')
args.append('"'+outFile+'"')
command = " ".join(args)
print command
returncode,output = check_output(command, True)
print output
# delete temporary files
for f in [part1, part2]:
if os.path.exists(f):
os.remove(f)