Calling ArcHydro Tools

986
0
05-03-2012 12:58 PM
MarkBoucher
Occasional Contributor III
The code below is a combination of a Model Builder Export and my attempt to revise it. I've done rudimetary python programing, but not much arcpy until now. Any help you toss my way would be helpful...

The aim is to extract part of a DEM by mask a then call ArcHydro tools to do in arcpy what seems to crash in Model Builder. Code below extracts the DEM (rawdem) and adds it to the mxd. I'm happy to get this far.

The image at the bottom shows the Toolbox "tree".

The code fails to complete DEM Reconditioning. My gut tells me I just don't understand how to use the Import command, etc.

I get the following messages:

[PHP]Executing: MakeRawdem
Start Time: Thu May 03 13:28:59 2012
Running script MakeRawdem...Extracting rawdem using mask
DEM Reconditioning<type 'exceptions.AttributeError'>: 'module' object has no attribute 'Terrain_Processing'
Failed to execute (MakeRawdem).
Failed at Thu May 03 13:40:56 2012 (Elapsed Time: 11 minutes 57 seconds)[/PHP]

# ---------------------------------------------------------------------------
# Make_rawdem.py
# Created on: 2012-05-01 14:50:42.00000
#   (generated by ArcGIS/ModelBuilder)
# Description: 
# ---------------------------------------------------------------------------


# Import arcpy module
import arcpy


# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")


#Set some settings
arcpy.env.overwriteOutput = True
arcpy.env.extent = "Mask"


# Define Directories
mxdDir = r"P:/ArcHydro/Z3B_SR_at_SR/"
rastDir = r"P:/ArcHydro/Z3B_SR_at_SR/UpperSR/"
vectDir = r"P:/ArcHydro/Z3B_SR_at_SR/UpperSR.gdb/UpperSR/"


# Local variables:
cc_ac_dem = r"P:/GIS USERS - Development/FC/Hydrology/Watershed GIS/DEMs/CC_AC_DEM/cc_ac_dem"
agreestream = r"P:/GIS USERS - Development/FC/Hydrology/Projects/Drainage Inventory for AgreeStream/agreestream.shp"
Innerwalls = r"P:/GIS USERS - Development/FC/Hydrology/Projects/Drainage Inventory for AgreeStream/innerwalls.shp"


# More Local variables:
Mask = "Mask"
rawdem = mxdDir + "rawdem"
agreedem = rastDir + "agreedem"
WalledDEM = rastDir + "WalledDEM"
fil = rastDir + "fil"
stop = 0


The Code below
## Process: Extract by Mask
if stop == 1: 
    arcpy.AddMessage("Skip Extracting rawdem using mask")
if stop == 0:
    arcpy.AddMessage("Extracting rawdem using mask")
    arcpy.env.extent = "Mask"
    arcpy.gp.ExtractByMask_sa(cc_ac_dem, Mask, rawdem)
    
    # Add layer to mxd - Change next line
    putin = rawdem
    mxd = arcpy.mapping.MapDocument("CURRENT")
    df = arcpy.mapping.ListDataFrames(mxd,'*')[0]
    print "mxd"
    addLayer = arcpy.mapping.Layer(putin)
    arcpy.mapping.AddLayer(df, addLayer)
    arcpy.RefreshActiveView()
    arcpy.RefreshTOC()
    del mxd, addLayer
    
# Process: DEM Reconditioning
arcpy.AddMessage("DEM Reconditioning")
arcpy.ImportToolbox("C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Arc Hydro Tools.tbx", "archydrotools")
arcpy.Terrain_Processing.DEMReconditioning(rawdem, agreestream, "5", "10", "1000", agreedem, "NEGATIVE_NO")
   
# Process: Build Walls
arcpy.AddMessage("Build Walls")
arcpy.BuildWalls(agreedem, "500", "0", "0", WalledDEM, "", Innerwalls, agreestream)

 # Process: Fill Sinks
arcpy.AddMessage("Fill Sinks")
arcpy.FillSinks(WalledDEM, fil, "", "", "ISSINK_NO")


0 Kudos
0 Replies