Layer name in new field after merge

6585
9
Jump to solution
09-10-2013 12:36 AM
GeorgHohberg1
New Contributor II
I have 50 polygons named P1 to P50 which I want to merge. In another table I have area names associated to P1 - P50. When merging the polygons I cannot find any way to keep the layer names of the origional polygons in order to assign the area names to them. Is there a way to write the layer names of the original polygons in the resulting attribute table?

Thanks for your help in advance!
0 Kudos
1 Solution

Accepted Solutions
GeorgHohberg1
New Contributor II
Hey jbarrette,

thanks for your reply. I was talking about 50 layers with one polygon in each.
I solved the problem myself, though. I used "parse path" in the model builder for "reading" the name of each layer and then added it as an attribute to the single polygon layers before merging them.

View solution in original post

0 Kudos
9 Replies
JeffBarrette
Esri Regular Contributor
I'm not clear on the following:

I have 50 polygons named P1 to P50 which I want to merge.

I cannot find any way to keep the layer names of the origional polygons


Does this mean that you have 50 polygon feature classes (aka layers) or is this a single feature class with 50 polygons?

Jeff
0 Kudos
GeorgHohberg1
New Contributor II
Hey jbarrette,

thanks for your reply. I was talking about 50 layers with one polygon in each.
I solved the problem myself, though. I used "parse path" in the model builder for "reading" the name of each layer and then added it as an attribute to the single polygon layers before merging them.
0 Kudos
JasonLi1
New Contributor

Not sure if you'll remember this after 6 years, can you explain what you've done to achieve this? I'm currently trying to do this very thing

0 Kudos
GeorgHohberg1
New Contributor II

Jason,

I dont't remember what I did, but I could send you the toolbox I used back then and you can figure it out yourself. In order to be able to send you a message you have to follow me, I think. Responding directly to your email did not work.

Georg

0 Kudos
JasonLi1
New Contributor

that'd be helpful, i just followed you back

0 Kudos
JohnBranum
New Contributor III

Hi guys -

I'm also trying to do the exact same thing.  Can I get in on this?

Thanks,

Johnny

0 Kudos
KevinWyjad
New Contributor

Hi Jason, I'm also trying to do this same thing. Did you sort it out, and if so, would you mind sharing?

0 Kudos
David_Kimball
New Contributor II

For anyone coming across this question (8 years later), this functionality is now available in the ArcGIS Pro Merge (Data Management) tool: https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/merge.htm

The tool has an "Add source information to output" checkbox - if you check it, it'll add a field named MERGE_SRC to the output:

The values in the MERGE_SRC field will indicate the input dataset path or layer name that is the source of each record in the output.

When I used it, I added layers to the tool from my Map, and the values in the resulting MERGE_SRC field looked like "GroupName\LayerName" (as named in the Map's Contents list). I haven't tried it with data added to the tool directly from browsing - maybe it puts the full pathname if you do it that way.

DamB99
by
New Contributor

To enhance the answer from David above. This option gives you only the layer name if you use drop down menu in Merge tool. If you browse to the file using Browse button it gives you the data path. However, it is very easy to include absolute path to the layers you are merging with only couple of lines in Python window (or if you create the actual Python script) without a need to use tedious Browse button in Merge tool.

Usual workflow is that your project contains at least one Map frame (data frame) and more often than that many layers beside the ones you want to merge. So best way is to create Group Layer where you put only layers that you want to merge. Having this then just open Python window (View > Python window) and paste the code from below with slight modification to the Python window.

 

proj = arcpy.mp.ArcGISProject('CURRENT')
# You might have many data frames in your project and you don't know which position in your list has. Change line item.name == "Map": to the name that you have. Default is Map but you might have anything
for index, item in enumerate(proj.listMaps()):
    if item.name == "Map":
        # You want to process only relevant Data Frame (aka Map)
        mf = proj.listMaps()[index]
        mfl = mf.listLayers()
lyr_names = []
for ly in mfl:
    # Change to your Group Layer name. So Merging to whatever you have
    if ly.isGroupLayer and ly.name == "Merging":
        lyrs = ly.listLayers()
        for lyr in lyrs:
            desc = arcpy.Describe(lyr)
            # arcpy.Describe catalogPath gives you the full path to data. So also the extension .shp for ESRI Shapefile if you have any
            lyr_names.append(desc.catalogPath)
# Because you are passing the full path to this tool it will write the absolute path and not the layer name.
# Change the output path (in this case D:\testing\testing2022\test.gdb\bbb) to whatever fits you
arcpy.management.Merge(lyr_names, r"D:\testing\testing2022\test.gdb\bbb", "" , "ADD_SOURCE_INFO")