ERROR 001156 on CopyFeatures_management

427
3
Jump to solution
03-04-2020 08:45 AM
JamesCrandall
MVP Frequent Contributor

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
0 Kudos
1 Solution

Accepted Solutions
JamesCrandall
MVP Frequent Contributor

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.

View solution in original post

0 Kudos
3 Replies
DanPatterson_Retired
MVP Emeritus

"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

JamesCrandall
MVP Frequent Contributor

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

0 Kudos
JamesCrandall
MVP Frequent Contributor

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.

0 Kudos