GISHydroNXT System Documentation

#*********************************************************************************
# Author:       UMD
# Date:         24-07-2018
# Modified:     n/a
# Classes:      AddStreams() 
# Functions:    n/a
# Modules:      arcpy
# Comments:     n/a
#*********************************************************************************
class AddStreams(object):
    """Implementation for GISHydroNXT_addin.button6 (Button)"""
    def __init__(self):
        self.enabled = False
        self.checked = False
    def onClick(self):
        arcpy.env.scratchWorkspace = scratchfolder
        arcpy.env.workspace = optfolder
        #*******************************************************************************************************        
        # add traced streams to view -- addOutputsToMap 
        #*******************************************************************************************************
        arcpy.env.addOutputsToMap = True
        arcpy.env.extent = "MAXOF"
        arcpy.Merge_management(optfolder + "/AddasStreams.shp",optfolder + "/StrmMerge.shp") # no apparent benefit of using merge
        arcpy.env.snapRaster = optfolder + "/flowacc"
        arcpy.FeatureToRaster_conversion(optfolder + "/StrmMerge.shp","Id",optfolder + "/ModStr","#")
        ModStr = arcpy.sa.Times(optfolder + "/ModStr",optfolder + "/basingrid")
        Streams = arcpy.sa.Con(ModStr == 0, 1)
        traced = arcpy.sa.Times(Streams,optfolder + "/basingrid")
        traced.save(optfolder + "/ModStreams") # add it to TOC
        modstreams = optfolder + "/ModStreams"

        #*******************************************************************************************************
        # turn layers ON/OFF in current data frame
        #*******************************************************************************************************
        mxd = arcpy.mapping.MapDocument("CURRENT")
        df = arcpy.mapping.ListDataFrames(mxd)[0]
        layers = arcpy.mapping.ListLayers(mxd, "", df)
        modlayer = arcpy.mapping.Layer(modstreams) # creating new layer
        arcpy.mapping.AddLayer(df, modlayer, "TOP")
        for lyr in layers:
            if lyr.name == "StrmMerge":
                arcpy.mapping.RemoveLayer(df, lyr)
            if lyr.name == "flowdir_dem":
                arcpy.mapping.RemoveLayer(df, lyr)
            if lyr.name == "line":
                arcpy.mapping.RemoveLayer(df, lyr)
            if lyr.name == "ModStr":
                arcpy.mapping.RemoveLayer(df, lyr)
            if lyr.name == "ModStreams":
                arcpy.ApplySymbologyFromLayer_management(lyr,r"" + Directory + "/data/mdfiles/legends/ModStreams.lyr")
            if lyr.name == "AddasStreams":
                lyr.visible = False

        arcpy.RefreshTOC()
        arcpy.RefreshActiveView()

        #*******************************************************************************************************
        # Turn Add streams OFF and Delineate Subwatersheds ON
        #*******************************************************************************************************

        tool4.enabled = False
        tool5.enabled = True
        button5.enabled = True
        button6.enabled = False
        button8.enabled = True