Trouble using Merge in arcpy - only one featureclass (out of 8) being output after merge

998
4
06-30-2017 12:22 PM
HannesZiegler2
Occasional Contributor II

I'm attempting to use the merge function arcpy.management.Merge(inputs, output) but I am not getting the results I expect. I have a list of featureclasses (all polygon, all have the same fields) in the in_memory workspace:

['in_memory\\polygon_D0511', 'in_memory\\polygon_D0510', 'in_memory\\polygon_D0512', 'in_memory\\polygon_D3239', 'in_memory\\polygon_D0514', 'in_memory\\polygon_D0515', 'in_memory\\polygon_D0513', 'in_memory\\polygon_D0509']

and I am using that as my inputs. The output is in a local geodatabase. When I run the merge tool in the script, my output only contains the feature from 'in_memory\\polygon_D3239', and nothing else. I've looked in my in_memory workspace using the arcpy.ListFeatureClasses() function and found that all featureclasses listed are there. I'm at a loss.. can anybody shed some light on this?

Thank you so much for any help at all!

 

Hannes

Tags (2)
0 Kudos
4 Replies
DanPatterson_Retired
MVP Esteemed Contributor

Run the merge tool manually, then go to the Results window and check the syntax etc if the manual method works.

HannesZiegler2
Occasional Contributor II

Hi Dan, thank you for the suggestion. I tried this after changing my script to save to a file geodatabase (instead of the in_memory workspace) and the merge worked just fine. However, attempting to do this same operation in script did not work even when using a file geodatabase instead of the in_memory workspace.

From the merge tool documentation I can see that the input should be a list of data filepaths, which is exactly what I am using for the input. The following code snippet is essentially* what I am doing in the script

damarea = "C:\\temp.gdb

damarea_list = ['in_memory\\polygon_D0511', 'in_memory\\polygon_D0510', 'in_memory\\polygon_D0512', 'in_memory\\polygon_D3239', 'in_memory\\polygon_D0514', 'in_memory\\polygon_D0515', 'in_memory\\polygon_D0513', 'in_memory\\polygon_D0509']

arcpy.env.workspace = "in_memory"

arcpy.management.Merge(damarea_list, damarea)

*I am leaving out a for loop where I first develop the individual featureclasses and then append them to the final list that you see in damarea_list.

The field mapping parameter is optional and since all input featureclasses have the exact same fields, I do not think I need it for the merge tool to work?

P.S. I did see that when I export to python from model builder, the input featureclasses is not provided as a list, but as a string with filepaths separated by a semicolon (;). I tried this in the script and it also did not work. Any other ideas?? I am at a loss and appreciate any help I can get here.


Thank you

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

The parameters would be a semi-colon list of strings, but you parse the string.

a_list = "some;big;long;string;of;files".split(";")

a_list
Out[2]: ['some', 'big', 'long', 'string', 'of', 'files']

I am not convinced that the inmemory workspace is the best for this.  If saving to a geodatabase worked, keep using it, do the merge there and use Copy tool to copy/move the results to its ultimate destination, then Delete the temporary geodatabase.... something about the double-backslashes is ringing a bell... try single then abandon in_memory if that doesn't work

0 Kudos
Justin_P
New Contributor III

I have this exact same problem and it's getting really frustrating troubleshooting something that should be so basic. Do you remember if this was ever solved? Any other ideas Dan Patterson‌? It only includes one feature class in the merge output in both ArcGIS Pro and ArcMap.

0 Kudos