GISHydroNXT System Documentation

#*********************************************************************************
# Author:       UMD
# Date:         24-07-2018
# Modified:     n/a
# Classes:      ResetWatershed() 
# Functions:    n/a
# Modules:      arcpy ; os
# Comments:     n/a
#*********************************************************************************
class ResetWatershed(object):
    """Implementation for GISHydroNXT_addin.button1 (Button)"""
    def __init__(self):
        self.enabled = False
        self.checked = False
    def onClick(self):
        arcpy.env.scratchWorkspace = scratchfolder
        arcpy.env.workspace = optfolder
        #*******************************************************************************************************
        # Remove watershed layer from data frame and Delete all temp files pertaining to watershed delineation
        #*******************************************************************************************************
        if os.path.exists(optfolder + "/aux_folder/curvenum_aux"):
            arcpy.env.addOutputsToMap = False
            arcpy.Delete_management(optfolder + "curveNumber","")
            arcpy.CopyRaster_management(optfolder + "/aux_folder/curvenum_aux", optfolder + "curveNumber")
            arcpy.Delete_management(optfolder + "/aux_folder/curvenum_aux","")
        if os.path.exists(optfolder + "/aux_folder/landuse_aux"):
            arcpy.env.addOutputsToMap = True
            arcpy.Delete_management(optfolder + "landuse","")
            arcpy.CopyRaster_management(optfolder + "/aux_folder/landuse_aux", optfolder + "landuse")
            arcpy.Delete_management(optfolder + "/aux_folder/landuse_aux","")
        arcpy.env.addOutputsToMap = True
        mxd = arcpy.mapping.MapDocument("CURRENT")
        df = arcpy.mapping.ListDataFrames(mxd)[0]
        tables = arcpy.mapping.ListTableViews(mxd, "", df)
        layers = arcpy.mapping.ListLayers(mxd, "", df)
        for lyr in layers:
            if lyr.name == "watershed":
                arcpy.mapping.RemoveLayer(df, lyr)
            if lyr.name == "landuse":
                lyr.visible = False
            if lyr.name == "outletpoint":
                arcpy.mapping.RemoveLayer(df, lyr)
            if lyr.name == "outletpoly":
                arcpy.mapping.RemoveLayer(df, lyr)
            if lyr.name == "flowdir":
                arcpy.mapping.RemoveLayer(df, lyr)
            if lyr.name == "outlet_ws":
                arcpy.mapping.RemoveLayer(df, lyr)

        for tbl in tables:
            if tbl.name == "thevTab":
                arcpy.mapping.RemoveTableView(df, tbl)

        arcpy.RefreshTOC()
        arcpy.RefreshActiveView()

        #*******************************************************************************************************
        # Delete files from optfolder
        #*******************************************************************************************************
        # Basin Stat file names
        #********************************************
        basingrid  = optfolder + "/basingrid"
        watershed  = optfolder + "/watershed.shp"
        maxlength  = optfolder + "/maxlength"
        outcell    = optfolder + "/outcell"
        outletpoly = optfolder + "/outletpoly.shp"
        outletpoint= optfolder + "/outletpoint.shp"
        thevtab    = optfolder + "/thevTab.dbf"
        limegrid   = optfolder + "/limegrid"
        wats_prov  = optfolder + "/wats_prov.shp"
        prov_int   = optfolder + "/prov_int.shp"
        wats_lime  = optfolder + "/wats_lime.shp"
        lime_int   = optfolder + "/lime_int.shp"
        basinstat  = optfolder + "/basinstat.txt"
        landslope  = optfolder + "/slope_calc/landslope" # can"t delete it with "slope_calc" folder so a separate delete here
        old_lime   = optfolder + "/limegrid_old.shp"
        flowdir    = optfolder + "/flowdir"
        outlet_ws  = optfolder + "/outlet_ws.shp"
        outletcell = optfolder + "/outletcell"

        if os.path.exists(flowdir):
            arcpy.Delete_management(flowdir,"")
        if os.path.exists(outletcell):
            arcpy.Delete_management(outletcell,"")
        if os.path.exists(outlet_ws):
            arcpy.Delete_management(outlet_ws,"")
        if os.path.exists(basingrid):
            arcpy.Delete_management(basingrid,"")
        if os.path.exists(watershed):
            arcpy.Delete_management(watershed,"")
        if os.path.exists(maxlength):
            arcpy.Delete_management(maxlength,"")
        if os.path.exists(outcell):
            arcpy.Delete_management(outcell,"")
        if os.path.exists(outletpoly):
            arcpy.Delete_management(outletpoly,"")
        if os.path.exists(outletpoint):
            arcpy.Delete_management(outletpoint,"")
        if os.path.exists(thevtab):
            arcpy.Delete_management(thevtab,"")
        if os.path.exists(limegrid):
            arcpy.Delete_management(limegrid,"")
        if os.path.exists(wats_prov):
            arcpy.Delete_management(wats_prov,"")
        if os.path.exists(prov_int):
            arcpy.Delete_management(prov_int,"")
        if os.path.exists(wats_lime):
            arcpy.Delete_management(wats_lime,"")
        if os.path.exists(lime_int):
            arcpy.Delete_management(lime_int,"")
        if os.path.exists(basinstat):
            arcpy.Delete_management(basinstat,"")
        if os.path.exists(landslope):
            arcpy.Delete_management(landslope,"")
        if os.path.exists(landslope):
            arcpy.Delete_management(old_lime,"")
        if os.path.exists(thevtab):
            arcpy.Delete_management(thevtab,"")

        # Delete "slope_calc" folder
        slope_calc = optfolder + "/slope_calc"
        if os.path.exists(slope_calc):
            shutil.rmtree(slope_calc)

        # Thomas Discharge file names
        #********************************************
        outletbuff = optfolder + "/outletbuffer.shp"
        gagefield  = optfolder + "/gagefield.shp"
        thomasdisc = optfolder + "/frdischarges.txt"
        mask_ints  = optfolder + "/mask_ints.shp"
        gauge_ol   = optfolder + "/gauge_outlet.shp"

        if os.path.exists(outletbuff):
            arcpy.Delete_management(outletbuff,"")
        if os.path.exists(gagefield):
            arcpy.Delete_management(gagefield,"")
        if os.path.exists(thomasdisc):
            arcpy.Delete_management(thomasdisc,"")
        if os.path.exists(mask_ints):
            arcpy.Delete_management(mask_ints,"")
        if os.path.exists(gauge_ol):
            arcpy.Delete_management(gauge_ol,"")

        # Delete "tasker" folder
        tasker     = optfolder + "/tasker"
        if os.path.exists(tasker):
            shutil.rmtree(tasker)

        # Delete "basincomp" folder
        basincomp     = optfolder + "/basincomp"
        if os.path.exists(basincomp):
            shutil.rmtree(basincomp)

        #*******************************************************************************************************
        # turn watershed delineation OFF and basin stat ON
        #*******************************************************************************************************
        tool2.enabled = True
        tool3.enabled = False
        button1.enabled = False
        button2.enabled = False
        button3.enabled = False
        button4.enabled = False # added on 10-22-2017 to turn off basin composition
        button5_1.enabled = False
        button6.enabled = False
        tool4.enabled = False
        tool7.enabled = False