I downloaded your data and Python script. When I first ran it, I got the following error:
Traceback <SPAN class="punctuation token">(</SPAN>most recent call last<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> File <SPAN class="string token">"<string>"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">45</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="operator token"><</SPAN>module<SPAN class="operator token">></SPAN> File <SPAN class="string token">"r:\arcgis\pro\Resources\arcpy\arcpy\conversion.py"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">2568</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> PolygonToRaster <SPAN class="keyword token">raise</SPAN> e File <SPAN class="string token">"r:\arcgis\pro\Resources\arcpy\arcpy\conversion.py"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">2565</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> PolygonToRaster retval <SPAN class="operator token">=</SPAN> convertArcObjectToPythonObject<SPAN class="punctuation token">(</SPAN>gp<SPAN class="punctuation token">.</SPAN>PolygonToRaster_conversion<SPAN class="punctuation token">(</SPAN><SPAN class="operator token">*</SPAN>gp_fixargs<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>in_features<SPAN class="punctuation token">,</SPAN> value_field<SPAN class="punctuation token">,</SPAN> out_rasterdataset<SPAN class="punctuation token">,</SPAN> cell_assignment<SPAN class="punctuation token">,</SPAN> priority_field<SPAN class="punctuation token">,</SPAN> cellsize<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> File <SPAN class="string token">"r:\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">511</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="operator token"><</SPAN><SPAN class="keyword token">lambda</SPAN><SPAN class="operator token">></SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="keyword token">lambda</SPAN> <SPAN class="operator token">*</SPAN>args<SPAN class="punctuation token">:</SPAN> val<SPAN class="punctuation token">(</SPAN><SPAN class="operator token">*</SPAN>gp_fixargs<SPAN class="punctuation token">(</SPAN>args<SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> arcgisscripting<SPAN class="punctuation token">.</SPAN>ExecuteError<SPAN class="punctuation token">:</SPAN> Failed to execute<SPAN class="punctuation token">.</SPAN> Parameters are <SPAN class="operator token">not</SPAN> valid<SPAN class="punctuation token">.</SPAN> ERROR <SPAN class="number token">000728</SPAN><SPAN class="punctuation token">:</SPAN> Field design_elevation does <SPAN class="operator token">not</SPAN> exist within table Failed to execute <SPAN class="punctuation token">(</SPAN>PolygonToRaster<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
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 <SPAN class="punctuation token">(</SPAN>most recent call last<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> File <SPAN class="string token">"R:\Temp\foo\Marsh_creation_fill_volume_tool.py"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">58</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="operator token"><</SPAN>module<SPAN class="operator token">></SPAN> depth_classified <SPAN class="operator token">=</SPAN> Con<SPAN class="punctuation token">(</SPAN>Raster<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"deep_water"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">></SPAN> max_depth<SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN> File <SPAN class="string token">"r:\arcgis\pro\Resources\arcpy\arcpy\sa\Raster.py"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">79</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> __new__ <SPAN class="keyword token">return</SPAN> super<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>__new__<SPAN class="punctuation token">(</SPAN>cls<SPAN class="punctuation token">,</SPAN> in_raster<SPAN class="punctuation token">,</SPAN> is_multidimensional<SPAN class="punctuation token">)</SPAN> RuntimeError<SPAN class="punctuation token">:</SPAN> ERROR <SPAN class="number token">000732</SPAN><SPAN class="punctuation token">:</SPAN> Input Raster<SPAN class="punctuation token">:</SPAN> Dataset deep_water does <SPAN class="operator token">not</SPAN> exist <SPAN class="operator token">or</SPAN> <SPAN class="keyword token">is</SPAN> <SPAN class="operator token">not</SPAN> supported Failed to execute <SPAN class="punctuation token">(</SPAN>Script<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
This error made me realize you are passing strings of variable names instead of the the variables themselves. For example, the following
depth_classified <SPAN class="operator token">=</SPAN> Con<SPAN class="punctuation token">(</SPAN>Raster<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"deep_water"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">></SPAN> max_depth<SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
should be
depth_classified <SPAN class="operator token">=</SPAN> Con<SPAN class="punctuation token">(</SPAN>Raster<SPAN class="punctuation token">(</SPAN>deep_water<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">></SPAN> max_depth<SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
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!
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.)
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
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.
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.