arcpy.Merge_management behaves differently in tool vs. script?

322
2
07-16-2014 05:49 AM
HåvardMoe
New Contributor III

Hey all,

I have a file geodatabase with a number of feature classes (Polyline ZM) + a table listing feature classes. There are polyline features not listed, and list items without a polyline. What I'd want to do is to:

1. Create a list of the feature classes in the geodatabase that correspond with those listed in the table

2. Merge these to a new feature class in a new file geodatabase.

The first part is solved, but I'm having some issues with the Merge_management function when running it from a script. I have successfully created a merged feature class using the merge tool from ArcMap, and the merged feature class holds 168 objects. Now, when I do this through a script I also get a merged feature class, but only 110 of the 168 objects... ?

I've checked some of the features added in/left out, but can't see any difference.

Having exported the ArcMap merge results via pythin snippet I can't see the input into the fucntion being any different in the two runs.

Have anyone seen this kind of behaviour and/or see a possible explanation?

Reply
0 Kudos
2 Replies
ToddUlery
Occasional Contributor

Hi Håvard,

Would like to investigate your task a little further.

Could you post what the arcpy call to the Merge_managment as you have it?

I can't recall this exact behavior, but know that it is tedious working with the Merge.

It is quite possible an issue with the field mapping.

I also found that this was better designed to use a model, but it can be work in a script. Just needs more 'TLC' given the Field Mapping part.

When you run it in Arc Map; just make sure there are no Queries. Just always a second thought sometimes; or even Selections on the data.

Reply
0 Kudos
HåvardMoe
New Contributor III

Well, I can try...

The arcmap tool snippet code looks like this:

arcpy.Merge_management("C:/work/database1.gdb/ADLB;C:/work/database1.gdb/ALGB;C:/work/database1.gdb/ALLB;C:/work/database1.gdb/ALNB;C:/work/database1.gdb/ASRB;C:/work/database1.gdb/BRAB;C:/work/database1.gdb/BREB;C:/work/database1.gdb/BRGB;C:/work/database1.gdb/DOVB;C:/work/database1.gdb/DRMB;C:/work/database1.gdb/FILB;C:/work/database1.gdb/FLEB;C:/work/database1.gdb/FLMB;C:/work/database1.gdb/GARB;C:/work/database1.gdb/GJKB;C:/work/database1.gdb/HARB;C:/work/database1.gdb/HVDB;C:/work/database1.gdb/KRAB;C:/work/database1.gdb/KVGB;C:/work/database1.gdb/MERB;C:/work/database1.gdb/MIDB;C:/work/database1.gdb/MINB;C:/work/database1.gdb/NAMB;C:/work/database1.gdb/NORB;C:/work/database1.gdb/NSIB;C:/work/database1.gdb/NUMB;C:/work/database1.gdb/OBOL;C:/work/database1.gdb/OBVL;C:/work/database1.gdb/OFTB;C:/work/database1.gdb/OFTB_KAT;C:/work/database1.gdb/RANB;C:/work/database1.gdb/RAUB;C:/work/database1.gdb/ROAB;C:/work/database1.gdb/ROSB;C:/work/database1.gdb/SOLB;C:/work/database1.gdb/SORB;C:/work/database1.gdb/SORB_DNE;C:/work/database1.gdb/SPIB;C:/work/database1.gdb/STLB;C:/work/database1.gdb/STLB_SAV;C:/work/database1.gdb/TINB;C:/work/database1.gdb/TINB_NTD;C:/work/database1.gdb/URHB;C:/work/database1.gdb/VALB;C:/work/database1.gdb/VESB","C:/work/database2.gdb/Merged_data","""FIELD1 "FIELD1" true false false 254 Text 0 0 ,First,#,C:/work/database1.gdb/ADLB,FIELD1,-1,-1,C:/work/database1.gdb/ALGB,FIELD1,-1,-1,C:/work/database1.gdb/ALLB,FIELD1,-1,-1,C:/work/database1.gdb/ALNB,FIELD1,-1,-1,C:/work/database1.gdb/ASRB,FIELD1,-1,-1,C:/work/database1.gdb/BRAB,FIELD1,-1,-1,C:/work/database1.gdb/BREB,FIELD1,-1,-1,C:/work/database1.gdb/BRGB,FIELD1,-1,-1,C:/work/database1.gdb/DOVB,FIELD1,-1,-1,C:/work/database1.gdb/DRMB,FIELD1,-1,-1,C:/work/database1.gdb/FILB,FIELD1,-1,-1,C:/work/database1.gdb/FLEB,FIELD1,-1,-1,C:/work/database1.gdb/FLMB,FIELD1,-1,-1,C:/work/database1.gdb/GARB,FIELD1,-1,-1,C:/work/database1.gdb/GJKB,FIELD1,-1,-1,C:/work/database1.gdb/HARB,FIELD1,-1,-1,C:/work/database1.gdb/HVDB,FIELD1,-1,-1,C:/work/database1.gdb/KRAB,FIELD1,-1,-1,C:/work/database1.gdb/KVGB,FIELD1,-1,-1,C:/work/database1.gdb/MERB,FIELD1,-1,-1,C:/work/database1.gdb/MIDB,FIELD1,-1,-1,C:/work/database1.gdb/MINB,FIELD1,-1,-1,C:/work/database1.gdb/NAMB,FIELD1,-1,-1,C:/work/database1.gdb/NORB,FIELD1,-1,-1,C:/work/database1.gdb/NSIB,FIELD1,-1,-1,C:/work/database1.gdb/NUMB,FIELD1,-1,-1,C:/work/database1.gdb/OBOL,FIELD1,-1,-1,C:/work/database1.gdb/OBVL,FIELD1,-1,-1,C:/work/database1.gdb/OFTB,FIELD1,-1,-1,C:/work/database1.gdb/OFTB_KAT,FIELD1,-1,-1,C:/work/database1.gdb/RANB,FIELD1,-1,-1,C:/work/database1.gdb/RAUB,FIELD1,-1,-1,C:/work/database1.gdb/ROAB,FIELD1,-1,-1,C:/work/database1.gdb/ROSB,FIELD1,-1,-1,C:/work/database1.gdb/SOLB,FIELD1,-1,-1,C:/work/database1.gdb/SORB,FIELD1,-1,-1,C:/work/database1.gdb/SORB_DNE,FIELD1,-1,-1,C:/work/database1.gdb/SPIB,FIELD1,-1,-1,C:/work/database1.gdb/STLB,FIELD1,-1,-1,C:/work/database1.gdb/STLB_SAV,FIELD1,-1,-1,C:/work/database1.gdb/TINB,FIELD1,-1,-1,C:/work/database1.gdb/TINB_NTD,FIELD1,-1,-1,C:/work/database1.gdb/URHB,FIELD1,-1,-1,C:/work/database1.gdb/VALB,FIELD1,-1,-1,C:/work/database1.gdb/VESB,FIELD1,-1,-1;Shape_Length "Shape_Length" false true true 8 Double 0 0 ,First,#,C:/work/database1.gdb/ADLB,Shape_Length,-1,-1,C:/work/database1.gdb/ALGB,Shape_Length,-1,-1,C:/work/database1.gdb/ALLB,Shape_Length,-1,-1,C:/work/database1.gdb/ALNB,Shape_Length,-1,-1,C:/work/database1.gdb/ASRB,Shape_Length,-1,-1,C:/work/database1.gdb/BRAB,Shape_Length,-1,-1,C:/work/database1.gdb/BREB,Shape_Length,-1,-1,C:/work/database1.gdb/BRGB,Shape_Length,-1,-1,C:/work/database1.gdb/DOVB,Shape_Length,-1,-1,C:/work/database1.gdb/DRMB,Shape_Length,-1,-1,C:/work/database1.gdb/FILB,Shape_Length,-1,-1,C:/work/database1.gdb/FLEB,Shape_Length,-1,-1,C:/work/database1.gdb/FLMB,Shape_Length,-1,-1,C:/work/database1.gdb/GARB,Shape_Length,-1,-1,C:/work/database1.gdb/GJKB,Shape_Length,-1,-1,C:/work/database1.gdb/HARB,Shape_Length,-1,-1,C:/work/database1.gdb/HVDB,Shape_Length,-1,-1,C:/work/database1.gdb/KRAB,Shape_Length,-1,-1,C:/work/database1.gdb/KVGB,Shape_Length,-1,-1,C:/work/database1.gdb/MERB,Shape_Length,-1,-1,C:/work/database1.gdb/MIDB,Shape_Length,-1,-1,C:/work/database1.gdb/MINB,Shape_Length,-1,-1,C:/work/database1.gdb/NAMB,Shape_Length,-1,-1,C:/work/database1.gdb/NORB,Shape_Length,-1,-1,C:/work/database1.gdb/NSIB,Shape_Length,-1,-1,C:/work/database1.gdb/NUMB,Shape_Length,-1,-1,C:/work/database1.gdb/OBOL,Shape_Length,-1,-1,C:/work/database1.gdb/OBVL,Shape_Length,-1,-1,C:/work/database1.gdb/OFTB,Shape_Length,-1,-1,C:/work/database1.gdb/OFTB_KAT,Shape_Length,-1,-1,C:/work/database1.gdb/RANB,Shape_Length,-1,-1,C:/work/database1.gdb/RAUB,Shape_Length,-1,-1,C:/work/database1.gdb/ROAB,Shape_Length,-1,-1,C:/work/database1.gdb/ROSB,Shape_Length,-1,-1,C:/work/database1.gdb/SOLB,Shape_Length,-1,-1,C:/work/database1.gdb/SORB,Shape_Length,-1,-1,C:/work/database1.gdb/SORB_DNE,Shape_Length,-1,-1,C:/work/database1.gdb/SPIB,Shape_Length,-1,-1,C:/work/database1.gdb/STLB,Shape_Length,-1,-1,C:/work/database1.gdb/STLB_SAV,Shape_Length,-1,-1,C:/work/database1.gdb/TINB,Shape_Length,-1,-1,C:/work/database1.gdb/TINB_NTD,Shape_Length,-1,-1,C:/work/database1.gdb/URHB,Shape_Length,-1,-1,C:/work/database1.gdb/VALB,Shape_Length,-1,-1,C:/work/database1.gdb/VESB,Shape_Length,-1,-1""")

In the script I build the inputs into the tool by looping a list of the features I want:

arcpy.Merge_management(fclist, fc_merged, fmlist)

I print the content of the fclist and fmlist variables during the script, and it looks just like the above to me:

fclist:

"C:\work\database1.gdb\ALNB;C:\work\database1.gdb\ADLB;C:\work\database1.gdb\ASRB;C:\work\database1.gdb\BRGB;C:\work\database1.gdb\BRAB;C:\work\database1.gdb\BREB;C:\work\database1.gdb\DOVB;C:\work\database1.gdb\DRMB;C:\work\database1.gdb\FILB;C:\work\database1.gdb\FLEB;C:\work\database1.gdb\FLMB;C:\work\database1.gdb\GARB;C:\work\database1.gdb\GJKB;C:\work\database1.gdb\ALLB;C:\work\database1.gdb\MINB;C:\work\database1.gdb\HARB;C:\work\database1.gdb\HVDB;C:\work\database1.gdb\KVGB;C:\work\database1.gdb\KRAB;C:\work\database1.gdb\MERB;C:\work\database1.gdb\NAMB;C:\work\database1.gdb\NORB;C:\work\database1.gdb\NUMB;C:\work\database1.gdb\OFTB;C:\work\database1.gdb\OFTB_KAT;C:\work\database1.gdb\RANB;C:\work\database1.gdb\RAUB;C:\work\database1.gdb\ROAB;C:\work\database1.gdb\ROSB;C:\work\database1.gdb\MIDB;C:\work\database1.gdb\NSIB;C:\work\database1.gdb\SOLB;C:\work\database1.gdb\SPIB;C:\work\database1.gdb\STLB;C:\work\database1.gdb\STLB_SAV;C:\work\database1.gdb\SORB;C:\work\database1.gdb\SORB_DNE;C:\work\database1.gdb\TINB;C:\work\database1.gdb\TINB_NTD;C:\work\database1.gdb\URHB;C:\work\database1.gdb\VALB;C:\work\database1.gdb\VESB;C:\work\database1.gdb\OBVL;C:\work\database1.gdb\OBOL;C:\work\database1.gdb\ALGB"

fmlist:

"FIELD1 "FIELD1" True False False 254 Text 0 0 ,First,#,C:\work\database1.gdb\ALNB,FIELD1,-1,-1,C:\work\database1.gdb\ADLB,FIELD1,-1,-1,C:\work\database1.gdb\ASRB,FIELD1,-1,-1,C:\work\database1.gdb\BRGB,FIELD1,-1,-1,C:\work\database1.gdb\BRAB,FIELD1,-1,-1,C:\work\database1.gdb\BREB,FIELD1,-1,-1,C:\work\database1.gdb\DOVB,FIELD1,-1,-1,C:\work\database1.gdb\DRMB,FIELD1,-1,-1,C:\work\database1.gdb\FILB,FIELD1,-1,-1,C:\work\database1.gdb\FLEB,FIELD1,-1,-1,C:\work\database1.gdb\FLMB,FIELD1,-1,-1,C:\work\database1.gdb\GARB,FIELD1,-1,-1,C:\work\database1.gdb\GJKB,FIELD1,-1,-1,C:\work\database1.gdb\ALLB,FIELD1,-1,-1,C:\work\database1.gdb\MINB,FIELD1,-1,-1,C:\work\database1.gdb\HARB,FIELD1,-1,-1,C:\work\database1.gdb\HVDB,FIELD1,-1,-1,C:\work\database1.gdb\KVGB,FIELD1,-1,-1,C:\work\database1.gdb\KRAB,FIELD1,-1,-1,C:\work\database1.gdb\MERB,FIELD1,-1,-1,C:\work\database1.gdb\NAMB,FIELD1,-1,-1,C:\work\database1.gdb\NORB,FIELD1,-1,-1,C:\work\database1.gdb\NUMB,FIELD1,-1,-1,C:\work\database1.gdb\OFTB,FIELD1,-1,-1,C:\work\database1.gdb\OFTB_KAT,FIELD1,-1,-1,C:\work\database1.gdb\RANB,FIELD1,-1,-1,C:\work\database1.gdb\RAUB,FIELD1,-1,-1,C:\work\database1.gdb\ROAB,FIELD1,-1,-1,C:\work\database1.gdb\ROSB,FIELD1,-1,-1,C:\work\database1.gdb\MIDB,FIELD1,-1,-1,C:\work\database1.gdb\NSIB,FIELD1,-1,-1,C:\work\database1.gdb\SOLB,FIELD1,-1,-1,C:\work\database1.gdb\SPIB,FIELD1,-1,-1,C:\work\database1.gdb\STLB,FIELD1,-1,-1,C:\work\database1.gdb\STLB_SAV,FIELD1,-1,-1,C:\work\database1.gdb\SORB,FIELD1,-1,-1,C:\work\database1.gdb\SORB_DNE,FIELD1,-1,-1,C:\work\database1.gdb\TINB,FIELD1,-1,-1,C:\work\database1.gdb\TINB_NTD,FIELD1,-1,-1,C:\work\database1.gdb\URHB,FIELD1,-1,-1,C:\work\database1.gdb\VALB,FIELD1,-1,-1,C:\work\database1.gdb\VESB,FIELD1,-1,-1,C:\work\database1.gdb\OBVL,FIELD1,-1,-1,C:\work\database1.gdb\OBOL,FIELD1,-1,-1,C:\work\database1.gdb\ALGB,FIELD1,-1,-1;Shape_Length "Shape_Length" False True True 8 Double 0 0 ,First,#,C:\work\database1.gdb\ALNB,Shape_Length,-1,-1,C:\work\database1.gdb\ADLB,Shape_Length,-1,-1,C:\work\database1.gdb\ASRB,Shape_Length,-1,-1,C:\work\database1.gdb\BRGB,Shape_Length,-1,-1,C:\work\database1.gdb\BRAB,Shape_Length,-1,-1,C:\work\database1.gdb\BREB,Shape_Length,-1,-1,C:\work\database1.gdb\DOVB,Shape_Length,-1,-1,C:\work\database1.gdb\DRMB,Shape_Length,-1,-1,C:\work\database1.gdb\FILB,Shape_Length,-1,-1,C:\work\database1.gdb\FLEB,Shape_Length,-1,-1,C:\work\database1.gdb\FLMB,Shape_Length,-1,-1,C:\work\database1.gdb\GARB,Shape_Length,-1,-1,C:\work\database1.gdb\GJKB,Shape_Length,-1,-1,C:\work\database1.gdb\ALLB,Shape_Length,-1,-1,C:\work\database1.gdb\MINB,Shape_Length,-1,-1,C:\work\database1.gdb\HARB,Shape_Length,-1,-1,C:\work\database1.gdb\HVDB,Shape_Length,-1,-1,C:\work\database1.gdb\KVGB,Shape_Length,-1,-1,C:\work\database1.gdb\KRAB,Shape_Length,-1,-1,C:\work\database1.gdb\MERB,Shape_Length,-1,-1,C:\work\database1.gdb\NAMB,Shape_Length,-1,-1,C:\work\database1.gdb\NORB,Shape_Length,-1,-1,C:\work\database1.gdb\NUMB,Shape_Length,-1,-1,C:\work\database1.gdb\OFTB,Shape_Length,-1,-1,C:\work\database1.gdb\OFTB_KAT,Shape_Length,-1,-1,C:\work\database1.gdb\RANB,Shape_Length,-1,-1,C:\work\database1.gdb\RAUB,Shape_Length,-1,-1,C:\work\database1.gdb\ROAB,Shape_Length,-1,-1,C:\work\database1.gdb\ROSB,Shape_Length,-1,-1,C:\work\database1.gdb\MIDB,Shape_Length,-1,-1,C:\work\database1.gdb\NSIB,Shape_Length,-1,-1,C:\work\database1.gdb\SOLB,Shape_Length,-1,-1,C:\work\database1.gdb\SPIB,Shape_Length,-1,-1,C:\work\database1.gdb\STLB,Shape_Length,-1,-1,C:\work\database1.gdb\STLB_SAV,Shape_Length,-1,-1,C:\work\database1.gdb\SORB,Shape_Length,-1,-1,C:\work\database1.gdb\SORB_DNE,Shape_Length,-1,-1,C:\work\database1.gdb\TINB,Shape_Length,-1,-1,C:\work\database1.gdb\TINB_NTD,Shape_Length,-1,-1,C:\work\database1.gdb\URHB,Shape_Length,-1,-1,C:\work\database1.gdb\VALB,Shape_Length,-1,-1,C:\work\database1.gdb\VESB,Shape_Length,-1,-1,C:\work\database1.gdb\OBVL,Shape_Length,-1,-1,C:\work\database1.gdb\OBOL,Shape_Length,-1,-1,C:\work\database1.gdb\ALGB,Shape_Length,-1,-1"

I thought the field mapping might be the cause, but I can't for the life of me see any differences between the two...

Reply
0 Kudos