-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector180to360.py
More file actions
99 lines (96 loc) · 3.29 KB
/
Vector180to360.py
File metadata and controls
99 lines (96 loc) · 3.29 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import os
import subprocess
import sys
inFile = sys.argv[1]
print "processing:", inFile
ogr2ogrFile = r"C:\OSGeo4W64\bin\ogr2ogr.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 shapefile
part1 = inFile.split(os.extsep)[0] + "_pt1.shp"
part2 = inFile.split(os.extsep)[0] + "_pt2.shp"
part2shifted = inFile.split(os.extsep)[0] + "_pt2s.shp"
outFile = inFile.split(os.extsep)[0] + "_360.shp"
if not os.path.exists(outFile):
# clip part 1
args = []
args.append('"'+ogr2ogrFile+'"')
args.append('-f')
args.append('"ESRI Shapefile"')
args.append('"'+part1+'"')
args.append('"'+inFile+'"')
args.append('-clipsrc 0 -90 180 90')
args.append('-skipfailures')
args.append('-progress')
#args.append('-nlt POINT')
command = " ".join(args)
print command
returncode,output = check_output(command, True)
print output
# clip part 2
args = []
args.append('"'+ogr2ogrFile+'"')
args.append('-f')
args.append('"ESRI Shapefile"')
args.append('"'+part2+'"')
args.append('"'+inFile+'"')
args.append('-clipsrc -180 -90 0 90')
args.append('-skipfailures')
args.append('-progress')
#args.append('-nlt POINT')
command = " ".join(args)
print command
returncode,output = check_output(command, True)
print output
# shift part 2 by -360
args = []
args.append('"'+ogr2ogrFile+'"')
args.append('-f')
args.append('"ESRI Shapefile"')
args.append('"'+part2shifted+'"')
args.append('"'+part2+'"')
args.append('-dialect sqlite -sql "SELECT ShiftCoords(Geometry,360,0), * FROM')
args.append(os.path.basename(part2).split(os.extsep)[0] + '"')
args.append('-progress')
command = " ".join(args)
print command
returncode,output = check_output(command, True)
print output
# write part 1 to output
args = []
args.append('"'+ogr2ogrFile+'"')
args.append('-f')
args.append('"ESRI Shapefile"')
args.append('"'+outFile+'"')
args.append('"'+part1+'"')
args.append('-progress')
command = " ".join(args)
print command
returncode,output = check_output(command, True)
print output
# write part 2 to output
args = []
args.append('"'+ogr2ogrFile+'"')
args.append('-f')
args.append('"ESRI Shapefile"')
args.append('-update -append')
args.append('"'+outFile+'"')
args.append('"'+part2shifted+'"')
args.append('-progress')
command = " ".join(args)
print command
returncode,output = check_output(command, True)
print output
# delete temporary files
for f in [os.path.basename(f) for f in [part1, part2, part2shifted]]:
for g in os.listdir(os.path.dirname(inFile)):
if g.split(os.extsep)[0] == f.split(os.extsep)[0]:
if os.path.exists(os.path.join(os.path.dirname(inFile), g)):
os.remove(os.path.join(os.path.dirname(inFile), g))