2

ArcGIS 10.2, Windows 10

this is the line that fails:

arcpy.SelectLayerByLocation_management(WRS_layer, "INTERSECT", gridLayer, "", "NEW_SELECTION")

The WRS_layer is in a file gdb, the gridLayer is in an SDE gdb. Both are polygon feature classes. SDE layers are being edited by a user-initiated edit session, but in this addin button there is no arcpy.da.Editor. The SelectByLocation will work fine for a while, and then starts giving an error message:

Traceback (most recent call last):
File "C:\Users\...\ESRI\Desktop10.2\AssemblyCache\{1E...D8E}\NORDIS_Landsat.py", line 432, in onClick
   arcpy.SelectLayerByLocation_management(WRS_layer, "INTERSECT", progressLayerName, "", "NEW_SELECTION")
File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\management.py", line 6812, in SelectLayerByLocation
    raise e
ExecuteError: ERROR 999999: Error executing function.
General function failure
General function failure [WRS2_Nordis]
Failed to execute (SelectLayerByLocation).

Here is the referenced line in management.py

6806      from arcpy.geoprocessing._base import gp, gp_fixargs
6807    from arcpy.arcobjects.arcobjectconversion import convertArcObjectToPythonObject
6808    try:
6809        retval = convertArcObjectToPythonObject(gp.SelectLayerByLocation_management(*gp_fixargs((in_layer, overlap_type, select_features, search_distance, selection_type), True)))
6810        return retval
6811    except Exception, e:
6812        raise e

Arcmap doesn't crash, but only a restart of ArcMap solves the problem. I don't think this is a code problem, but I hope that someone else has experienced something similar and can suggest a cause and/or solution.

EDIT: as requested, here is the top part of the button's code immed after def onClick(self)

mxd = arcpy.mapping.MapDocument("CURRENT")
# SET SOME VARIABLES
Error = False
WRS_layer          = "WRS2_Nordis"
WRS_fields         = ["PR"]
username           = getpass.getuser().lower()
rastersPresent     = []
rastersMissing     = []

# 0. VERIFY THAT THE REQUIRED LAYERS ARE PRESENT IN THE MXD.
print
layersPresent = []
for lyr in arcpy.mapping.ListLayers(mxd):
    layersPresent.append(lyr.name)
for lyrReqd in (WRS_layer, progressLayerName):
    if not lyrReqd in layersPresent:
        Error = True
        print "ERROR: cannot find layer  ", lyrReqd, "  in the TOC."

# 1. GET THE SELECTED GRID CELL
d = arcpy.Describe(progressLayerName)
if len(d.FIDSet) == 0:
    ProgressGrid_Select = 0
else:
    ProgressGrid_Select = len(d.FIDSet.split(";"))
if ProgressGrid_Select <> 1:
    print " You have", str(ProgressGrid_Select), " ProgressGrid cells selected  -- should be exactly 1."
    Error = True

# 2. GET THE INTERSECTING WRS SCENES
# make a WRS list of lists, with PathRow

if not Error:
    # SelectLayerByLocation HONOURS THE SELECTION SET IN in_layer
    print 'DEBUG: attempting SelectLayerByLocation_management(WRS_layer, "INTERSECT", progressLayerName, "", "NEW_SELECTION")'
    arcpy.SelectLayerByLocation_management(WRS_layer, "INTERSECT", progressLayerName, "", "NEW_SELECTION")
    #  make list of WRS scenes, with PR (data type Long)
    WRS_scenes = []
    # SearchCursor (in_table, field_names, {where_clause}, {spatial_reference}, {explode_to_points}, {sql_clause})
    with arcpy.da.SearchCursor(WRS_layer,WRS_fields) as cursor:
        for row in cursor:
            WRS_scenes.append(row[0])

    if len(WRS_scenes) == 0:
        print "No WRS_scenes intersect with selected Progress Grid cell."
        Error = True
    else:
        print "Found " + str(len(WRS_scenes)) + " WRS scenes for selected progress cell:"
        WRS_scenes.sort()
        prs = ''
        for pr in WRS_scenes:
            prs += ("  " + str(pr))
        print prs
    print
12
  • Those cursed ERROR 999999 messages. This error could mean anything that the developer didn't anticipate originally. Try calling repair geometry on your gridLayer and WRS_layer feature class just in case a bowtie or incorrect ring orientation has the selection engine confused. If there's changes in these datasets expected call as part of the script or if they're static run repair in catalog just once on both. Commented May 3, 2016 at 22:20
  • Is this in any loop in your addin or does the user have to press a button or click on the map to run a tool each time. Are you cleaning up everything before completing each button press or tool operation? Do you have an extension going? With at least 432 lines of code in your addin you more than likely have created code than is a bit more complex sequence than a simple SelectLayerByAttribute operation. The greater the complexity, the more likely you are not cleaning up after yourself. Also, is the user able to select more features than SDE memory is configured to return? Commented May 3, 2016 at 23:08
  • Can you please include a snippet around line 432 of your code rather than from management.py?
    – Midavalo
    Commented May 3, 2016 at 23:54
  • I wonder if it could be a projection/coordinate system issue. Do they have the same spatial reference? Also, turning off background processing sometimes works better for more complex geoprocessing resources.arcgis.com/en/help/main/10.2/index.html#//…
    – dslamb
    Commented May 4, 2016 at 12:53
  • @Micheal OK, I've manually repaired geometry on the WRS_layer, it's not editable so I shouldn't need to call it in the script. The gridLayer is in the SDE, so can't repair geometry there, it's supposed to be handled by the SDE.
    – AMurray
    Commented May 4, 2016 at 16:41

0