Hi all,
Not sure what I missing here. I am creating in_memory feature layer from the result of a arcpy.Intersect_analysis() operation and then attempting to apply CopyFeatures on that feature layer (it has an sql applied to it in order to filter prior to CopyFeatures).
Of note in code below: setting up itsctRESULT variable to output to disk and everything works but fails with said Error when set to output to in_memory.
I'd rather have it all operate in the in_memory workspace as it saves a bathtub full of processing time.
landFC = os.path.join("in_memory", "landsToProc")
arcpy.JSONToFeatures_conversion(jFileLands, landFC)
trackFC = os.path.join("in_memory", "tracksToProc")
arcpy.JSONToFeatures_conversion(jFileTracks, trackFC)
itsctRESULT = os.path.join(r"in_memory", "itsctRESULT")
#itsctRESULT = os.path.join(r"E:\someFolder", "itsctRESULT") <-doesn't cause error 001156 at CopyFeatures_management line below
arcpy.Intersect_analysis(["tracksToProc","landsToProc"], itsctRESULT, "ALL", "#", "POINT")
arcpy.AddField_management(itsctRESULT,'rel_objectid', "LONG")
arcpy.AddField_management(itsctRESULT,'PO', "TEXT", 50)
with arcpy.da.UpdateCursor(itsctRESULT,updFields) as cursor:
for row in cursor:
row[0] = purchaseOrder
row[1] = vendorNumber
inputFL = os.path.join("in_memory","fl_{0}".format(count))
outputFL = os.path.join("in_memory", "flResult_{0}".format(count))
sql = "Some Where Clause that filters correctly"
arcpy.MakeFeatureLayer_management(itsctRESULT, inputFL, sql)
arcpy.CopyFeatures_management(inputFL, outputFL) <- fails with ERROR 001156: Failed on input OID 1, could not write value '4500321321' to output field PO
Solved! Go to Solution.
I just moved the addfields and updatecursor processing after the CopyFeatures to in_memory step. For whatever reason it didn't honor the field lengths after adding fields.
"in_memory/itsctRESULT" Did you try something as simple as that. There doesn't appear to be any need for the os module at all . (it appears that the help uses forward slashes
The os.path.join() had taken care of some other issue in the past (can't remember exactly what) but from then on just became the standard way in all of my implementations. In any event, I tried and get the same ERROR: 001156.
Possibly this is related to a field mapping thing? It seems as tho that Intersect_analysis doesn't produce the same field lengths in the output to in_memory vs. to disk.
Result of ListFields to in_memory:
rel_objectid is a type of Integer with a length of 0
PO is a type of String with a length of 0
Vendor is a type of String with a length of 0
Same ListFields to same output but to disk:
rel_objectid is a type of Integer with a length of 4
PO is a type of String with a length of 255
Vendor is a type of String with a length of 255
I just moved the addfields and updatecursor processing after the CopyFeatures to in_memory step. For whatever reason it didn't honor the field lengths after adding fields.