Solved! Go to Solution.
I downloaded your data and Python script. When I first ran it, I got the following error:
Traceback (most recent call last):
File "<string>", line 45, in <module>
File "r:\arcgis\pro\Resources\arcpy\arcpy\conversion.py", line 2568, in PolygonToRaster
raise e
File "r:\arcgis\pro\Resources\arcpy\arcpy\conversion.py", line 2565, in PolygonToRaster
retval = convertArcObjectToPythonObject(gp.PolygonToRaster_conversion(*gp_fixargs((in_features, value_field, out_rasterdataset, cell_assignment, priority_field, cellsize), True)))
File "r:\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py", line 511, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000728: Field design_elevation does not exist within table
Failed to execute (PolygonToRaster).
I believe since you uploaded a shape file, the "design_elevation" field was truncated to "design_ele".
After double checking the field names and layer names were correct, I loaded the Python code into the interactive Python window using "Load Code", and everything worked fine. I got three new raster outputs.
I then tried running the script as a tool, but I got the following error:
Traceback (most recent call last):
File "R:\Temp\foo\Marsh_creation_fill_volume_tool.py", line 58, in <module>
depth_classified = Con(Raster("deep_water") > max_depth,0,1)
File "r:\arcgis\pro\Resources\arcpy\arcpy\sa\Raster.py", line 79, in __new__
return super().__new__(cls, in_raster, is_multidimensional)
RuntimeError: ERROR 000732: Input Raster: Dataset deep_water does not exist or is not supported
Failed to execute (Script)
This error made me realize you are passing strings of variable names instead of the the variables themselves. For example, the following
depth_classified = Con(Raster("deep_water") > max_depth,0,1)
should be
depth_classified = Con(Raster(deep_water) > max_depth,0,1)
Once I cleaned up the strings, the script ran as a script tool just fine. The reason the original code ran in the Interactive Python window with the strings is that layers were being created and added to the TOC when the tools were run from the Python window. The layers that got added had the names of your strings, and so when you pass a string the geoprocessing tool was picking it up and a layer and referencing back to the data set.
Only things I can think of are to check out the spatial analyst extension, and be explicit rather than from arcpy.sa import * (I assume since I don't really download people's zips - posting the code would get more traction) use arcpy.sa.Minus(..
Also I'd ensure that the rasters are properly cast into Raster objects to allow the raster algebra.
Here is the code. I have already been explicit with the import for spatial analyst.
I was under the impression from the documentation that if I used the arcpy.sa.Minus, etc. I didn't need to cast into raster first. Is that not correct? I also did see anything that would suggest which was better to use: arcpy.sa.Minus(ras1,ras2) or Raster(ras1)-Raster(ras2). Is one preferable?
Thanks,
Diana
Hi yes, this was before seeing your script, so apologies you're correct on most counts.
I can't see the spatial analyst extension being checked out? Which may be the issue since you can use it in immediate mode?
There are string-only paths specified but the arcpy env workspace is commented out?
I'm not sure of the new python sorting this out, but you may want to explicitly put your values as floats in-case of integer division happening (max_depth = 2.0 etc.)
I downloaded your data and Python script. When I first ran it, I got the following error:
Traceback (most recent call last):
File "<string>", line 45, in <module>
File "r:\arcgis\pro\Resources\arcpy\arcpy\conversion.py", line 2568, in PolygonToRaster
raise e
File "r:\arcgis\pro\Resources\arcpy\arcpy\conversion.py", line 2565, in PolygonToRaster
retval = convertArcObjectToPythonObject(gp.PolygonToRaster_conversion(*gp_fixargs((in_features, value_field, out_rasterdataset, cell_assignment, priority_field, cellsize), True)))
File "r:\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py", line 511, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000728: Field design_elevation does not exist within table
Failed to execute (PolygonToRaster).
I believe since you uploaded a shape file, the "design_elevation" field was truncated to "design_ele".
After double checking the field names and layer names were correct, I loaded the Python code into the interactive Python window using "Load Code", and everything worked fine. I got three new raster outputs.
I then tried running the script as a tool, but I got the following error:
Traceback (most recent call last):
File "R:\Temp\foo\Marsh_creation_fill_volume_tool.py", line 58, in <module>
depth_classified = Con(Raster("deep_water") > max_depth,0,1)
File "r:\arcgis\pro\Resources\arcpy\arcpy\sa\Raster.py", line 79, in __new__
return super().__new__(cls, in_raster, is_multidimensional)
RuntimeError: ERROR 000732: Input Raster: Dataset deep_water does not exist or is not supported
Failed to execute (Script)
This error made me realize you are passing strings of variable names instead of the the variables themselves. For example, the following
depth_classified = Con(Raster("deep_water") > max_depth,0,1)
should be
depth_classified = Con(Raster(deep_water) > max_depth,0,1)
Once I cleaned up the strings, the script ran as a script tool just fine. The reason the original code ran in the Interactive Python window with the strings is that layers were being created and added to the TOC when the tools were run from the Python window. The layers that got added had the names of your strings, and so when you pass a string the geoprocessing tool was picking it up and a layer and referencing back to the data set.
It seems like passing the variable names as strings was the issue. I've just run it through successfully twice in a row. Thanks to both of you for your help!