AnsweredAssumed Answered

Field calculation issue when using memory workspace

Question asked by tmichael81 on May 20, 2020
Latest reply on May 21, 2020 by jborgion

Hi all,

 

I'm working on a script that uses the 'memory' workspace as layers are being processed, and I've hit an issue when I try to execute a field calculation between joined layers.  I have included a script below that demonstrates the differences between workflows - the calculation will work fine if I create the feature layers from layers on disk, but will fail if the feature layers are created from layers in the memory workspace - testtype "fromdisk" works but testtype "frommemory" does not.

 

import arcpy

inLine = r"D:\TEMP\Output_20200520080600.gdb\LINE00240"
inPoint = r"D:\TEMP\Output_20200520080600.gdb\StructureJoin"

testtype = "fromdisk"

if testtype == "fromdisk":
    # Features are stored on disk
    # Feature layers are created from layers on disk
   
    print("Running disk workflow")

    # Make feature layers
    arcpy.MakeFeatureLayer_management(inLine, "LineFeature")
    arcpy.MakeFeatureLayer_management(inPoint, "StructureFeature")

    # Add join
    arcpy.AddJoin_management("LineFeature", "OBJECTID", "StructureFeature", "ORIG_FID", "KEEP_COMMON")

    # Calculate field
    in_field = "Field_Name"
    expression = '!StructureJoin.STRUCTURE_GUID!'
    arcpy.CalculateField_management("LineFeature", in_field, expression, "PYTHON3")

elif testtype == "frommemory":
    # Features are stored on disk
    # Make copy of data in memory
    # Feature layers are created from layers in memory

    print("Running memory workflow")
   
    # Copy features to memory
    arcpy.CopyFeatures_management(inLine, r"memory\Lines")
    arcpy.CopyFeatures_management(inPoint, r"memory\Structures")

    # Make feature layers
    arcpy.MakeFeatureLayer_management(r"memory\Lines", "LineFeature")
    arcpy.MakeFeatureLayer_management(r"memory\Structures", "StructureFeature")

    # Add join
    arcpy.AddJoin_management("LineFeature", "OBJECTID", "StructureFeature", "ORIG_FID", "KEEP_COMMON")

    # Calculate field
    in_field = "Field_Name"
    expression = '!Structures.STRUCTURE_GUID!'
    arcpy.CalculateField_management("LineFeature", in_field, expression, "PYTHON3")

 

The resulting error is:

Running memory workflow
Traceback (most recent call last):
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 4527, in CalculateField
retval = convertArcObjectToPythonObject(gp.CalculateField_management(*gp_fixargs((in_table, field, expression, expression_type, code_block, field_type), True)))
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 511, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: ERROR 999999: Something unexpected caused the tool to fail. Contact Esri Technical Support (http://esriurl.com/support) to Report a Bug, and refer to the error help for potential solutions or workarounds.
Failed to execute (CalculateField).

 

Do I need to do something different when using the memory workspace?

Outcomes