In my file geodatabase (C:\polygeo\test.gdb) I have two feature classes:
- PointsFC which has 400 points arranged in a 20x20 grid
- FishnetFC which has four polygons arranged in a 2x2 grid - this has a field called Name that has values FC1, FC2, FC3 and FC4
When I run the script below I expect that the Clip tool will be taking the shape geometry as a token (SHAPE@) from each polygon in FishnetFC in turn and using it to clip out 100 points from PointsFC into a separate feature class called FC1, FC2, FC3 and FC4 in the current workspace (C:\polygeo\test.gdb).
import arcpy
inputFC = "C:/temp/test.gdb/PointsFC"
splitFC = "C:/temp/test.gdb/FishnetFC"
splitField = "Name"
arcpy.env.workspace = "C:/temp/test.gdb"
arcpy.env.overwriteOutput = True
with arcpy.da.SearchCursor(splitFC,[splitField,"SHAPE@"]) as cursor:
for row in cursor:
print "Clipping " + row[0]
print str(row[1])
arcpy.Clip_analysis(inputFC,row[1],row[0])
print "Clip completed!"
print "Script finished!"
However, immediately after an uninstall/reinstall of ArcGIS 10.2.2 for Desktop (letting it install Python) I got the errors below from running it three times in IDLE:
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
Clipping FC1
<geoprocessing describe geometry object object at 0x026BFF20>
Traceback (most recent call last):
File "C:\temp\test.py", line 22, in <module>
arcpy.Clip_analysis(inputFC,row[1],row[0])
File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\analysis.py", line 56, in Clip
raise e
ExecuteError: ERROR 999999: Error executing function.
The table was not found. [FC1]
Failed to execute (Clip).
>>> ================================ RESTART ================================
>>>
Clipping FC1
<geoprocessing describe geometry object object at 0x0278FF20>
Traceback (most recent call last):
File "C:\temp\test.py", line 16, in <module>
arcpy.Clip_analysis(inputFC,row[1],row[0])
File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\analysis.py", line 56, in Clip
raise e
ExecuteError: ERROR 999999: Error executing function.
Failed to execute (Clip).
>>> ================================ RESTART ================================
>>>
Clipping FC1
<geoprocessing describe geometry object object at 0x0279FF20>
Traceback (most recent call last):
File "C:\temp\test.py", line 14, in <module>
arcpy.Clip_analysis(inputFC,row[1],row[0])
File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\analysis.py", line 56, in Clip
raise e
ExecuteError: ERROR 999999: Error executing function.
The table was not found. [FC1]
Failed to execute (Clip).
Does anyone know why? What confuses me is:
- On the first run, before which I made sure "C:/temp/test.gdb/FC1" did not exist, it complains that
The table was not found. [FC1]
and then leaves an empty point feature class called FC1 in the file geodatabase. - For the second run, I left FC1 in place, and the error message changed to make no such mention.
- For the third run I deleted FC1 and the message reverted to include
The table was not found. [FC1]
so I think this should be giving me a hint about what is astray but I am not yet sure what.
Test which generates its own data
To try and get something easy for anyone to test I just enhanced the above script to generate its own test data, and then to perform the desired processing.
If anyone runs this using ArcGIS 10.2.2 for Desktop (like me) or any version that is at least 10.1:
import arcpy
inputFC = "C:/temp/test.gdb/TEMP_label"
splitFC = "C:/temp/test.gdb/FishnetFC"
splitField = "Name"
if arcpy.Exists("C:/temp/test.gdb"):
arcpy.Delete_management("C:/temp/test.gdb")
arcpy.CreateFileGDB_management("C:/temp","test.gdb")
arcpy.CreateFishnet_management(out_feature_class="C:/temp/test.gdb/FishnetFC",
origin_coord="0 0",y_axis_coord="0 1",
cell_width="1",cell_height="1",
number_rows="2",number_columns="2",
corner_coord="#",labels="NO_LABELS",
template="#",geometry_type="POLYGON")
arcpy.AddField_management(in_table="C:/temp/test.gdb/FishnetFC",
field_name="Name",field_type="TEXT",
field_precision="#",field_scale="#",
field_length="10",field_alias="#",
field_is_nullable="NULLABLE",
field_is_required="NON_REQUIRED",field_domain="#")
arcpy.CalculateField_management(in_table="C:/temp/test.gdb/FishnetFC",
field="Name",
expression=""""FC" + str( !OID! )""",
expression_type="PYTHON_9.3",code_block="#")
arcpy.CreateFishnet_management(out_feature_class="C:/temp/test.gdb/TEMP",
origin_coord="0 0",y_axis_coord="0 1",
cell_width="0.1",cell_height="0.1",
number_rows="20",number_columns="20",
corner_coord="#",labels="LABELS",
template="#",geometry_type="POLYLINE")
arcpy.env.workspace = "C:/temp/test.gdb"
arcpy.env.overwriteOutput = True
with arcpy.da.SearchCursor(splitFC,[splitField,"SHAPE@"]) as cursor:
for row in cursor:
print "Clipping " + row[0]
print str(row[1])
name = row[0]
geom = row[1]
arcpy.Clip_analysis(inputFC,geom,name)
print "Clip completed!"
print "Script finished!"
I would expect them to see (based on my results):
>>> ================================ RESTART ================================
>>>
Clipping FC1
<geoprocessing describe geometry object object at 0x01DE7620>
Traceback (most recent call last):
File "C:\temp\test.py", line 44, in <module>
arcpy.Clip_analysis(inputFC,geom,name)
File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\analysis.py", line 56, in Clip
raise e
ExecuteError: ERROR 999999: Error executing function.
The table was not found. [FC1]
Failed to execute (Clip).