I am trying to run the Watershed Delineation tool in a Notebook cell within ArcGISPro 3.3. The tool runs fine from the Geoprocessing pane but if I copy the Python script to a Notebook cell it fails with the error: '
module 'arcpy' has no attribute 'archydropro'
I tried to import watersheddelineation. This appears to run but doesn't help. I tried to import arcyhydro and archydropro and both failed.
Solved! Go to Solution.
Kevin,
Please follow EXACTLY the parameter list as I provided. Not sure where you came up with the “DoDelineateWatershed” syntax, but it is not the correct list of parameters for the Watershed Delineation function (you have two extra parameters you are setting to None and the order is incorrect – throwing everything off). Also, I would not rely on relative paths to the input and output layers but would provide full path – e.g. instead of:
str_raster = “str.tif”
use:
str_raster = r”c:\\pathtoproject\\pathtorasters\\str.tif” (with correct paths of course).
That goes for both raster and vector layers.
You noted in your original post that the tool correctly works when run from the gp pane (otherwise I would have suggested to run it like that first to make sure all your inputs are correct). Before running it again (either through code or UI) check your input point FC (“mp” FC?) and set BATCHDONE field to 0 if need. Each time you successfully run watershed delineation on a point, its BATCHDONE will be set to 1 and will not be processed next time around you run that function.
Dean
Kevin,
Please review https://community.esri.com/t5/water-resources-documents/arc-hydro-calling-arc-hydro-tools-in-python-... for recommendations on how to run AH tools in python. The doc is a bit outdated, but covers the basics that should get you started. It does not have explicit Notebook section, but section 2.3 applies to Notebook implementation directly.
Specifically, for the watershed delineation function, the syntax should be something like (assuming that Arc Hydro tools are properly installed and operational on the system):
import arcpy
import watersheddelineation
#------------------------------------------------------------------------------------
# code to define all required parameters: in_dp, snap_distance, flowdir_raster, str_raster, strsnap_raster, catchment_fc, adjointcatchment_fc, out_wshfc, out_spp
# note that snap_distance should be defined as a string, e.g. “100” for 100 units.
#------------------------------------------------------------------------------------
# apply arc hydro watershed delineation for batch points
processor = watersheddelineation.WatershedDelineation()
processor.DebugLevel = 0
processor.bCallFromPYT = False
params = (in_dp, snap_distance, flowdir_raster, str_raster, strsnap_raster, catchment_fc, adjointcatchment_fc, out_wshfc, out_spp, None, None)
t_results = processor.execute(params, None)
# results are: (sOK, out_wshf, out_spp)
Dean
I tried this after viewing the list of variables for the watersheddelineation tool in the python window (see attached screen capture). This cell runs without an error but does not appear to produce any result:
import arcpy
import watersheddelineation
#------------------------------------------------------------------------------------
# code to define all required parameters: in_dp, snap_distance, flowdir_raster, str_raster, strsnap_raster, catchment_fc, adjointcatchment_fc, out_wshfc, out_spp
# note that snap_distance should be defined as a string, e.g. “100” for 100 units.
#------------------------------------------------------------------------------------
# apply arc hydro watershed delineation for batch points
in_dp='mp'
snap_distance='10'
flowdir_raster='fdr.tif'
str_raster='Str.tif'
strsnap_raster='Str.tif'
catchment_fc='Catchment'
adjointcatchment_fc='AdjointCatchment'
out_wshfc='wshed_out'
out_spp='wpt_out'
processor = watersheddelineation.WatershedDelineation()
processor.DebugLevel = 0
processor.bCallFromPYT = False
params = (in_dp, snap_distance, str_raster, strsnap_raster, catchment_fc, adjointcatchment_fc, flowdir_raster, None, None, out_wshfc, out_spp, None, None, None)
t_results = processor.execute(params, None)
# results are: (sOK, out_wshf, out_spp)
Kevin,
Please follow EXACTLY the parameter list as I provided. Not sure where you came up with the “DoDelineateWatershed” syntax, but it is not the correct list of parameters for the Watershed Delineation function (you have two extra parameters you are setting to None and the order is incorrect – throwing everything off). Also, I would not rely on relative paths to the input and output layers but would provide full path – e.g. instead of:
str_raster = “str.tif”
use:
str_raster = r”c:\\pathtoproject\\pathtorasters\\str.tif” (with correct paths of course).
That goes for both raster and vector layers.
You noted in your original post that the tool correctly works when run from the gp pane (otherwise I would have suggested to run it like that first to make sure all your inputs are correct). Before running it again (either through code or UI) check your input point FC (“mp” FC?) and set BATCHDONE field to 0 if need. Each time you successfully run watershed delineation on a point, its BATCHDONE will be set to 1 and will not be processed next time around you run that function.
Dean
The full path works.
The DoDeleateWaterhsed syntax came from running the watersheddelineation tool in the python window per a suggestion from archhydro@esri.com. It had 2 extra variables: 'hydroidfield' and 'drainidfield'. I don't think I need the python window now that it is running in a notebook cell.
Thanks for the help.