ArcHydro doesn't recognize workspace or target locations in Python ?

1302
1
03-13-2017 09:18 AM
Labels (1)
PeterWilson
Occasional Contributor III

I'm currently busy re-writing the following Python Module:

I have just realised that ArcHydro doesn't recognize the arcpy.env.workspace or the ArcHydroTools.SetTargetLocations("HydroConfig", "Layers", "RasterWorkspace", "VectorWorkspace")

'''
Created on March 13, 2017

ArcHydro Main Model

@author: PeterW
'''

# import system modules and site-packages
from pathlib import Path
import arcpy
import ArcHydroTools

# set arguments
rasters_workspace = r"E:\Projects\2016\G113386\ArcHydro\Model01\Layers01"
dem = r"E:\Projects\2016\G113386\DEM\raw"
fgdb_workspace = r"E:\Projects\2016\G113386\ArcHydro\Model01\Model01.gdb"


# check out extensions and set environment settings
arcpy.CheckOutExtension("Spatial")
arcpy.env.overwriteOutput = True


def rasters_main(rasters_workspace, dem):
    """ Create Rasters as part of ArcHydro Pre-processing"""
    # set raster workspace
    arcpy.env.workspace = rasters_workspace
    # set ArcHyro Target Locations for Raster and Vector Datasets
    ArcHydroTools.SetTargetLocations("HydroConfig", "Layers", rasters_workspace, fgdb_workspace) 
    # create Fil Sinks raster
    arcpy.AddMessage("Processing Fill Sinks")
    ArcHydroTools.FillSinks(dem, "fil")
    # create Flow Direction raster

rasters_main(rasters_workspace, dem)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Python Module: arcpy.env.workspace and ArcHydroTools.SetTargetLocations ignored by ArcHydro

Processing Fill Sinks
Traceback (most recent call last):
  File "E:\Python\Eclipse\2015\arcpy64bit\src\archydro\archydro_main_test.py", line 34, in <module>
    rasters_main(rasters_workspace, dem)
  File "E:\Python\Eclipse\2015\arcpy64bit\src\archydro\archydro_main_test.py", line 31, in rasters_main
    ArcHydroTools.FillSinks(dem, "fil")
  File "C:\Program Files\ESRI\WaterUtils\ArcHydro\bin\ArcHydroTools.py", line 6805, in FillSinks
    raise e
arcgisscripting.ExecuteError: You need to set either the geoprocessing Workspace or the Arc Hydro Raster Location before running the tool.
Failed to execute (FillSinks).

‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Error Message:

I'm currently using ArcGIS 10.3.1 and ArcHydroTools 10.3.0.78

0 Kudos
1 Reply
JohnHerold
New Contributor

I don't know if this will fix your problem, but I was having a similar issue (except with vector location instead of raster location) with ThinCrossSection tool even though I set the arcpy enviroment and ArcHydro's target locations.

The issue seems to be that you need a full path to a feature instead of just the name:

# This did not work for me
ArcHydroTools.ThinCrossSection("TEMP", "MaxNumberOfVertices", 500, output, report)

# This did
output = gdb_path + '\\' + output
report = gdb_path + '\\' + report
ArcHydroTools.ThinCrossSection("TEMP", "MaxNumberOfVertices", 500, output, report)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

And with this, I just had to set the arcpy workspace - I don't need to call SetTargetLocations from ArcHydro.

So specifically for yours, replacing 'fil' in the FillSinks call with the full path to 'fil' might work

0 Kudos