I am trying to determine the relative drainage area of two type of distinct wetlands. I am using these individual wetlands as the pour points for the watershed tool in ArcMap's spatial analyst toolbox. I need to perform this same analysis in multiple study areas, and tried to automate the process. The general process uses spatial analyst tools: Reclassify > RegionGroup > Watershed
The final code will loop through a number of polygons and clip each layer to the outline of the polygon. For now I am just putting together the general spatial analyst workflow.
path = r'G:\Flow_Adjacency_Analysis\TEST.gdb\Wetlands'
_Grouped_name = path+'_Grouped'
Grouped_wetlands = arcpy.sa.RegionGroup('Reclassified_wetlands', 'EIGHT', 'WITHIN', 'NO_LINK')
Grouped_wetlands.save(_Grouped_name)
out_watershed = arcpy.sa.Watershed("Flow_dir", _Grouped_name)
out_path = path + '_Watershed'
out_watershed.save(out_path)
When these operations were performed manually there was no attribute table for the watershed raster. This problem was solved using either 'Copy_Raster' or 'BuildAttributeTable' with no issue. Neither one of these approaches works in the python code however. Copy Raster produces Error 999999:
arcpy.management.CopyRaster(out_path,'wetland_DA' , None, None, 65535, "NONE", "NONE", "32_BIT_SIGNED", "NONE", "NONE", "GRID", "NONE")
C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py in
CopyRaster(in_raster, out_rasterdataset, config_keyword, background_value,
nodata_value, onebit_to_eightbit, colormap_to_RGB, pixel_type,
scale_pixel_value, RGB_to_Colormap, format, transform)
14292 return retval
14293 except Exception as e:
> 14294 raise e
14295
14296 @gptooldoc('CreateRandomRaster_management', None)
C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py in
CopyRaster(in_raster, out_rasterdataset, config_keyword, background_value,
nodata_value, onebit_to_eightbit, colormap_to_RGB, pixel_type,
scale_pixel_value, RGB_to_Colormap, format, transform)
14289 from arcpy.arcobjects.arcobjectconversion import
convertArcObjectToPythonObject
14290 try:
> 14291 retval = convertArcObjectToPythonObject(gp.CopyRaster_management(*gp_fixargs((in_raster,
out_rasterdataset, config_keyword, background_value, nodata_value,
onebit_to_eightbit, colormap_to_RGB, pixel_type, scale_pixel_value,
RGB_to_Colormap, format, transform), True)))
14292 return retval
14293 except Exception as e:
C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py in
<lambda>(*args)
494 val = getattr(self._gp, attr)
495 if callable(val):
--> 496 return lambda *args: val(*gp_fixargs(args, True))
497 else:
498 return convertArcObjectToPythonObject(val)
ExecuteError: ERROR 999999: Something unexpected caused the tool to fail.
Please refer to the error help for potential solutions, or contact Esri
Technical Support http://esriurl.com/support.
General function failure [wetland_DA]
The table was not found.
The table was not found. [fras_blk_Watersh_Flow1]
No spatial reference exists.
The table was not found. [wetland_DA]
Failed to execute (CopyRaster).
And Build Raster Attribute Table produces Error 000049:
arcpy.management.BuildRasterAttributeTable(out_path, "NONE")
ExecuteError: ERROR 000049: Failed to build attribute table
Failed to execute (BuildRasterAttributeTable).
Trying to access the raster layer directly using either a Search Cursor or a making a table from the raster using 'arcpy.MakeTableView_management' produces Error 000229:
tbl = arcpy.MakeTableView_management(out_watershed, 'test_tbl')
ExecuteError: ERROR 000229: Cannot open G:\Flow_Adjacency_Analysis_\TEST.gdb\Wetlands_Watershed'
Failed to execute (MakeTableView).
I am trying to troubleshoot these errors to try and fix this code. Given the number of different errors I don't know where to start. The raster exists in the gdb and doesn't have any existing locks. The process works without any errors when I do it manually in ArcGIS Pro.