3

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

enter image description here

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).
  • I have cloned your environment and the code and things are working fine. One thing that looks interesting is your path in the traceback <File "C:\polygeo\SelectByLocation.py">. Do you have your Python installed in the folder polygeo? The only plausible version of this error is that something goes wrong when the Python is trying to reference arcpy libraries with a wrong data path. Do other arcpy scripts work fine? Just try executing a simple arcpy script with a couple of arcpy.xx_yy GP tools to check. – Alex Tereshenkov Nov 16 '14 at 8:27
  • Thanks for testing @AlexTereshenkov The SelectByLocation.py should have been called SplitByLocation.py but after a rename the issues persists for me. Python is installed at the default location. Other arcpy scripts seem to be working fine but I had something (actually ModelBuilder) similarly non-reproducible last week in gis.stackexchange.com/questions/121653/… so I am thinking that I should bite the bullet and do an uninstall/reinstall rather than try to debug the install. – PolyGeo Nov 16 '14 at 9:16
  • Ah I see. What I was wondering though is why the arcpy SelectByLocation.py is located at C:\polygeo\. In the traceback, I get the arcpy path in ArcGIS like C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy. But reinstall could probably help for sure :D – Alex Tereshenkov Nov 16 '14 at 9:29
  • @AlexTereshenkov I did the uninstall/reinstall and changed my test slightly to what is now in the question but the problem still persists for me. Was your cloned environment also testing at 10.2.2? – PolyGeo Nov 17 '14 at 2:08
  • off-topic from your exact question, but the Split GP tool might make sense here (assuming you can afford a Big Desktop license) – Stephen Lead Nov 17 '14 at 2:15
3

I can't explain why Clip is failing when you pass in the geometry. It happens for me as well.

I can offer this workaround, though. Persist that geometry out to in_memory (or to disk), then clip with it.

with arcpy.da.SearchCursor(splitFC, [splitField,"SHAPE@"]) as cursor:
   for row in cursor:
       name = row[0]
       geom = row[1]
       in_memory_feature = "in_memory\\" + name
       # Create temporary in-memory feature class
       arcpy.management.CopyFeatures(geom, in_memory_feature)
       # Perform clip
       arcpy.analysis.Clip(inputFC, in_memory_feature, name + "_clip")
       # Delete temporary in-memory feature class
       arcpy.management.Delete(in_memory_feature)
  • Many thanks for reproducing this. If it has an NIM number are you able to provide it for tracking purposes? In the meantime your workaround works well but I was hoping to keep the code as concise as possible. – PolyGeo Nov 18 '14 at 0:55
2

I'm getting the same error in my Arc 10.2 installation. I've encountered issues in the past when using geometry objects with geoprocessing tools, as you're doing with the geom object from your cursor and the Clip tool. It's just ironic since this is almost exactly the example in the Esri help page. One solution is to avoid using geometry objects by exporting the clipping features to a feature class (either on disk or in memory) as KHibma showed in his answer. I've come up with an alternative.


After doing some testing, it seems like tools don't like operating on geometry objects without spatial reference information. I redefined the spatial reference in the input objects to WGS84:

spatialRef = arcpy.SpatialReference(4326)
for file in [inputFC,splitFC]:
    arcpy.DefineProjection_management(file, spatialRef)

But even when the geometry objects being read by the searchCursor have a spatial reference, it still throws the error. But for some reason, if you create an entirely new geometry object in memory, everything runs fine:

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 = arcpy.Polygon(row[1].getPart(0),spatialRef) #New geometry object with SR
        arcpy.Clip_analysis(inputFC,geom,name)
        print "Clip completed!"

screenshot

  • Many thanks for reproducing this. I had done some experimenting with adding a spatial reference but did not get to a successful workaround like you. I have gone with the workaround in @KHibma's answer because from this test I want to go to using multipart polygons in the Clip so, while trying to keep the code as concise as possible, the other workaround will enable me to keep Spatial References and dealing with multiple geometry parts out of the picture. I suspect your workaround would perform quicker but code conciseness rather than speed is more important in this instance. – PolyGeo Nov 18 '14 at 1:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.