Arcpy – Input of In-Memory Geometry Object to Dissolve Tool Throws Error 000732

arcpyerror-000732geometrygeoprocessingin-memory

In an arcpy script, I run a Union on a list of geometry objects. The output is set to an empty geometry object. The Union runs fine. What I am trying to do is then feed that output into the Dissolve tool. No matter how I format the input, I get the following error:

Parameters are not valid.
ERROR 000732: Input Features: Dataset in_memory\f8537CACB_AB51_4BDC_B8E7_0895F11E6AF0 does not exist or is not supported

ESRI help files indicate that tools set to output to an empty geometry object return a list of geometry objects. The output from the Union tool gives <Geometry object at 0x26d25910[0x27397068]> when queried with repr(). I have tried putting the Union result directly into the Dissolve tool and likewise the 0 index item from the result, seeing as it supposed to be a list. Both result in an error, the latter saying that a geometry object is not indexable. Here is a code snippet:

if len(lstHSGeoms) > 1:
            #Union geometries into one geometry
            lstHSUnionGeom = arcpy.Geometry()
            arcpy.Union_analysis(lstHSGeoms, lstHSUnionGeom, "ONLY_FID")
            arcpy.AddMessage('          lstHSUnionGeom:  %s' % repr(lstHSUnionGeom))
            lstHSOneGeom = arcpy.Geometry()
            arcpy.Dissolve_management(lstHSUnionGeom,lstHSOneGeom, None, None, "SINGLE_PART")
            hsOneGeom = lstHSOneGeom[0]

The list lstHSGeoms is a Python list of polygon geometries, which have checked out as valid. The Union runs, but the Dissovle doesn't. I'm stymied. BTW, I tried using an empty string for the fourth parameter of Dissolve (seeing that it is supposed to be a string type), but it didn't make a difference.

Best Answer

Setting the output of a geoprocessing tool to an emtpy arcpy.geometry object is not the standard method for using in-memory workspaces. Instead, you want to set the output of the Union to a string variable that references the "file name" of the in-memory feature dataset, almost exactly as if you were using a shapefile. The only difference is that instead of setting your variable to C:\temp\lstHSUnionGeom.shp you would use in_memory\lstHSUnionGeom. Here's the updated code:

if len(lstHSGeoms) > 1:
            #Union geometries into one geometry
            lstHSUnionGeom = "in_memory\\lstHSUnionGeom" #Two slashes required due to escape character
            arcpy.Union_analysis(lstHSGeoms, lstHSUnionGeom, "ONLY_FID")
            arcpy.AddMessage('          lstHSUnionGeom:  %s' % repr(lstHSUnionGeom))
            lstHSOneGeom = "in_memory\\lstHSOneGeom" #Two slashes required due to escape character
            arcpy.Dissolve_management(lstHSUnionGeom,lstHSOneGeom, None, None, "SINGLE_PART")
Related Question