hi all, I'm using PythonWin and also tried PyScripter to clip one polygon geodatabase feature class with each polygon in another polygon geodatabase feature class. I've used this code successfully before with other data but suddenly, with this particular dataset, it's giving me problems.
First I create a list (CatchmentIDLIst) from an item of unique values in the clip feature class, then loop through the polygons by selecting on each item in that list and setting that one as the present clip polygon. I know the list is being created successfully because it prints out correctly in the interactive window after I create it.
But for some reason, the clip (Clip_analysis) operation isn't working properly. Code below:
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> os
MyWorkspace <SPAN class="operator token">=</SPAN> <SPAN class="string token">"C:\stuff\PrecipitationFlooding/Norfolk"</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> <SPAN class="string token">"C:\stuff\PrecipitationFlooding\Norfolk\Norfolk_Data.gdb"</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> True
arcpy<SPAN class="punctuation token">.</SPAN><SPAN class="token function">MakeFeatureLayer_management</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Catchments_Polygons_Dissolve"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Norfolk_Catchment_FLayer"</SPAN><SPAN class="punctuation token">)</SPAN>
# Create list <SPAN class="keyword token">for</SPAN> all the Catchment ID values
CatchmentIDList <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN>
# Populate list <SPAN class="keyword token">with</SPAN> all the Catchment ID values
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN><SPAN class="token function">SearchCursor</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Catchments_Polygons_Dissolve"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"OBJECTID"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> CatchmentRowsCursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> eachCatchmentRow <SPAN class="keyword token">in</SPAN> CatchmentRowsCursor<SPAN class="punctuation token">:</SPAN>
CatchmentIDList<SPAN class="punctuation token">.</SPAN><SPAN class="token function">append</SPAN><SPAN class="punctuation token">(</SPAN>eachCatchmentRow<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
print <SPAN class="token function">str</SPAN><SPAN class="punctuation token">(</SPAN>CatchmentIDList<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">strip</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'[]'</SPAN><SPAN class="punctuation token">)</SPAN>
#############################################################
#############################################################
######### Iterate through each catchment ####################
#############################################################
#############################################################
<SPAN class="keyword token">for</SPAN> EachCatchmentID <SPAN class="keyword token">in</SPAN> CatchmentIDList<SPAN class="punctuation token">:</SPAN>
print <SPAN class="string token">"Catchment ID = "</SPAN><SPAN class="punctuation token">,</SPAN> EachCatchmentID
arcpy<SPAN class="punctuation token">.</SPAN><SPAN class="token function">SelectLayerByAttribute_management</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Norfolk_Catchment_FLayer"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"NEW_SELECTION"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"OBJECTID = "</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="token function">str</SPAN><SPAN class="punctuation token">(</SPAN>EachCatchmentID<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
NorfolkLandUseByCatchment <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Norfolk_Landuse"</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="token function">str</SPAN><SPAN class="punctuation token">(</SPAN>EachCatchmentID<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Clip_analysis</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Norfolk_LandUse_SPS"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"Norfolk_Catchment_FLayer"</SPAN><SPAN class="punctuation token">,</SPAN>NorfolkLandUseByCatchment<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></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
The exact error is:
Traceback (most recent call last):
File "C:\stuff\PrecipitationFlooding\flooding.py", line 38, in <module>
arcpy.Clip_analysis("Norfolk_LandUse_SPS","Norfolk_Catchment_FLayer",NorfolkLandUseByCatchment)
File "C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcPy\arcpy\analysis.py", line 56, in Clip
raise e
ExecuteError: ERROR 999999: Error executing function.
The table was not found.
The table was not found. [Norfolk_Landuse1]
The table was not found.
The table was not found. [Norfolk_Landuse1]
Invalid Topology [Topoengine error.]
Failed to execute (Clip).
I don't understand why it's trying to find a table "Norfolk_Landuse1". It should be creating that feature class "Norfolk_Landuse1", right?
Thanks much..
Dan