arcpy.Clip_analysis error (can't find the cause)

5882
13
05-01-2015 04:00 PM
MichaelSouffront
New Contributor III

I updated a script to clip wetlands data per county. Some counties work, but for others the Clip analysis fails.

Here is the code:

import arcpy
import time

# Start time
start = time.time()
print('Prepping wetlands county clipped data')

# Enivornment variables
arcpy.env.overwriteOutput = True
arcpy.env.workspace = 'in_memory'
arcpy.env.outputCoordinateSystem = arcpy.SpatialReference('NAD 1983 UTM Zone 12N')

# Input paths
countyPath = r'Counties'
wetlandsPath = r'UT_Wetlands'

# Output path
outFolder = r'output.gdb'

# Create feature dataset
wetlandsFolder = '{}/Wetlands'.format(outFolder)
if not arcpy.Exists(wetlandsFolder):
  arcpy.CreateFeatureDataset_management(outFolder, 'Wetlands')

arcpy.MakeFeatureLayer_management(countyPath, 'countyLayer')

maxCount = len(idList)
count = 1

countyRows = arcpy.SearchCursor(countyPath)
for countyRow in countyRows:

  county = str(countyRow.NAME).replace(' ', '_')
   
  outFile = '{}/Wetlands/{}_Wetlands'.format(outFolder, county)

  query = '"NAME" = \'' + str(countyRow.NAME) + '\''
  arcpy.SelectLayerByAttribute_management('countyLayer', 'NEW_SELECTION', query)

  print 'Clipping ' + str(count) + ' out of ' + str(maxCount)

  arcpy.Clip_analysis(wetlandsPath, 'countyLayer', outFile)

  arcpy.SelectLayerByAttribute_management('countyLayer', 'CLEAR_SELECTION')

  count += 1

  print 'Working on wetlands for ' + county.replace('_', ' ') + ' county...'

  # Here I create variables

  # Here I add new fields

  # Here I populate the new fields with the created variables

del countyRow, countyRows
   
# Finish
end = time.time()
print '\nFinished, run time', time.strftime('%M:%S', time.localtime(end - start))

The script will work until it gets to SANPETE county, which gives this error:

arcgisscripting.ExecuteError: ERROR 999999: Error executing function.

The table was not found.

The table was not found. [SANPETE_Wetlands]

The table was not found.

The table was not found. [SANPETE_Wetlands]

Invalid Topology [Incomplete void poly.]

Failed to execute (Clip).

I've tracked the error to the clip function. At first I thought there was an error in the syntax, then I thought arcpy was getting confused as to where to look for the created clipped feature because I was saving it in memory, then I thought maybe the wetlands data was just too big, or there is something wrong with the attribute data for the SANPETE county, but it's non of those. I tried skipping SANPETE but then it runs for a while and fails in BEAVER county.

I'm running out of ideas as to what it may be. I tried the clip manually in arcMap and it works.

Any suggestions as to what else to try or do you see anything I'm missing in the script?

Thanks,

Michael

Tags (2)
13 Replies
MichaelSouffront
New Contributor III

Running as standalone from Spyder, also tried Pyscripter, ArcGIS 10.3.

We did tried the .da cursors to see if that was it, but no.

See solution explained below.

0 Kudos
benberman
Occasional Contributor

As Curtis pointed out, it's tidier to build a list first and then loop through it. Why is the counter starting at 1, and not at 0 ?

0 Kudos
MichaelSouffront
New Contributor III

My coworker spent a couple of days on this and couldn't find the error either. At the end we just rewrote the whole thing differently.

The actual error was never found but at this does what we needed.

One thing we added that may have solved the problem was the simplify polygon function on the wetlands data. We believe that the wetlands data had some sliver in between counties or something like that, but there's still the exception that things ran fine when done manually so we will never know for sure.

Thank you all for your help anyway.

Michael

ThomasLaxson
New Contributor III

For anyone else who might come across this, an answer on StackExchange worked for me. "this is a resources issue"​. Doing whatever you can to use fewer resources; e.g.:

- Ensure you're in a 64-bit/background environment)

- Generalize/Simplify your geometries

- Repair geometries

- Use fgdb (my issue was that I was processing data in an .mdb that some dinosaur had sent me)

Best of luck.