-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgospatial_example.py
62 lines (51 loc) · 1.92 KB
/
gospatial_example.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
60
61
62
#!/usr/bin/env python
import sys
import gospatial as gs
def main():
try:
# Get the gospatial version number
# print(gs.version())
# List all available tools in gospatial
# print(gs.list_tools())
# Prints the gospatial help...a listing of available commands
# print(gs.help())
# Print the help documentation for the Aspect tool
# print(gs.tool_help("MaxElevationDeviation"))
# Prints the arguments used for running the FillDepressions tool
# print(gs.tool_args("FillDepressions"))
# Sets the working directory. If /the working dir is set, you don't
# need to specify complete file names (with paths) to tools that you run.
gs.set_working_dir("/Users/johnlindsay/Documents/data/")
# Run the Aspect tool, specifying the arguments.
name = "DeviationFromMean"
args = [
"gtopo30_arab_subduction.dep",
"out4.dep",
"100"
]
# Run the tool and check the return value
ret = gs.run_tool(name, args)
if ret != 0:
print("ERROR: return value={}".format(ret))
except:
print("Unexpected error:", sys.exc_info()[0])
raise
# Create a custom callback to process the text coming out of the tool.
# If a callback is not provided, it will simply print the output stream.
# A provided callback allows for custom processing of the output stream.
def callback(s):
try:
# print("{}".format(s))
if "%" in s:
str_array = s.split(" ")
label = s.replace(str_array[len(str_array)-1], "")
progress = int(str_array[len(str_array)-1].replace("%", "").strip())
print("Progress: {}%".format(progress))
else:
if "error" in s.lower():
print("ERROR: {}".format(s))
else:
print("{}".format(s))
except:
print(s)
main()