Solved! Go to Solution.
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
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
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
that'd be helpful, i just followed you back
Hi guys -
I'm also trying to do the exact same thing. Can I get in on this?
Thanks,
Johnny
Hi Jason, I'm also trying to do this same thing. Did you sort it out, and if so, would you mind sharing?
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.
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")