Skip to content

Commit 8f5af43

Browse files
committed
Initial implementation of ArcGIS tool for mass wasting potential computation
1 parent 2d007cc commit 8f5af43

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

ArcGISMassWastingPotential.py

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
__author__ = 'Pabitra'
2+
3+
import os
4+
import subprocess
5+
6+
import arcpy
7+
8+
# get the input parameters
9+
graip_database_file = arcpy.GetParameterAsText(0)
10+
desc = arcpy.Describe(graip_database_file)
11+
graip_database_file = str(desc.catalogPath)
12+
13+
drainpoint_shp_file = arcpy.GetParameterAsText(1)
14+
desc = arcpy.Describe(drainpoint_shp_file)
15+
drainpoint_shp_file = str(desc.catalogPath)
16+
17+
slp_raster_file = arcpy.GetParameterAsText(2)
18+
desc = arcpy.Describe(slp_raster_file)
19+
slp_raster_file = str(desc.catalogPath)
20+
alpha_value = arcpy.GetParameterAsText(3)
21+
22+
# optional inputs
23+
si_raster_file = arcpy.GetParameterAsText(4)
24+
if arcpy.Exists(si_raster_file):
25+
desc = arcpy.Describe(si_raster_file)
26+
si_raster_file = str(desc.catalogPath)
27+
28+
sic_raster_file = arcpy.GetParameterAsText(5)
29+
if arcpy.Exists(sic_raster_file):
30+
desc = arcpy.Describe(sic_raster_file)
31+
sic_raster_file = str(desc.catalogPath)
32+
33+
stream_dist_raster_file = arcpy.GetParameterAsText(6)
34+
if arcpy.Exists(stream_dist_raster_file):
35+
desc = arcpy.Describe(stream_dist_raster_file)
36+
stream_dist_raster_file = str(desc.catalogPath)
37+
38+
# construct command to execute
39+
current_script_dir = os.path.dirname(os.path.realpath(__file__))
40+
# put quotes around file paths in case they have spaces
41+
graip_database_file = '"' + graip_database_file + '"'
42+
drainpoint_shp_file = '"' + drainpoint_shp_file + '"'
43+
slp_raster_file = '"' + slp_raster_file + '"'
44+
if len(si_raster_file) > 0:
45+
si_raster_file = '"' + si_raster_file + '"'
46+
47+
if len(sic_raster_file) > 0:
48+
sic_raster_file = '"' + sic_raster_file + '"'
49+
50+
if len(stream_dist_raster_file) > 0:
51+
stream_dist_raster_file = '"' + stream_dist_raster_file + '"'
52+
53+
py_script_to_execute = os.path.join(current_script_dir, 'MassWastingPotential.py')
54+
py_script_to_execute = '"' + py_script_to_execute + '"'
55+
cmd = py_script_to_execute + \
56+
' --mdb ' + graip_database_file + \
57+
' --dp ' + drainpoint_shp_file + \
58+
' --slpd ' + slp_raster_file + \
59+
' --alpha ' + alpha_value
60+
61+
if len(si_raster_file) > 0:
62+
cmd += ' --si ' + si_raster_file
63+
64+
if len(sic_raster_file) > 0:
65+
cmd += ' --sic ' + sic_raster_file
66+
67+
if len(stream_dist_raster_file) > 0:
68+
cmd += ' --dist ' + stream_dist_raster_file
69+
70+
# show executing command
71+
arcpy.AddMessage('\nEXECUTING COMMAND:\n' + cmd)
72+
73+
# Capture the contents of shell command and print it to the arcgis dialog box
74+
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
75+
arcpy.AddMessage('\nProcess started:\n')
76+
start_message = "Please wait. It may take few seconds. Computation is in progress ..."
77+
arcpy.AddMessage(start_message)
78+
for line in process.stdout.readlines():
79+
if start_message not in line:
80+
arcpy.AddMessage(line)

GRAIP Tools.tbx

9 KB
Binary file not shown.

0 commit comments

Comments
 (0)