AnsweredAssumed Answered

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

Question asked by Msouff on May 1, 2015
Latest reply on May 3, 2016 by tlaxson

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?