0

I have a GeoDatabase with a handful of shapefiles. The contents are likely to change often, so I want to build a tool that allows me to merge all the shapefiles in the GDB into one layer.

This is what I currently have: enter image description here

However, I am not expecting this to work, as it seems like it would just grab one file each iteration and 'merge' it with itself. Is there a workaround so that it grabs all files from the GDB to merge them? I am using ArcGIS Desktop 10.5.

Jared
  • 335
  • 1
  • 10

1 Answers1

1

This is an arcpy solution rather than a ModelBuilder one but I believe it is pretty straightforward. To run it you just have to open the Python console in ArcMap and paste the following lines:

import arcpy

# specify the path to your GDB
arcpy.env.workspace = 'path/name.gdb'

# get all the Feature Classes in the GDB
fcs = arcpy.ListFeatureClasses()

# run the Merge tool
arcpy.Merge_management(inputs=fcs, output='merge_result')

This will create a feature class called merge_result in your GDB.

Marcelo Villa
  • 5,928
  • 2
  • 19
  • 38
  • I have a Spyder environment set up with Arcpy. Unfortunately, I get the following error when running it:

    ExecuteError: Failed to execute. Parameters are not valid. ERROR 000735: Input Datasets: Value is required Failed to execute (Merge).

    Also, when I do print(fcs) the output is 'None'. Any ideas?

    – Jared Jun 06 '19 at 15:14
  • It is possible that the path to your gdb is not correct. Can you show me how you declared the path? – Marcelo Villa Jun 06 '19 at 15:25
  • The issue was '/' vs. '' in declaring the path. Classic. Thanks for the help! – Jared Jun 06 '19 at 15:29
  • When declaring paths in Python make sure to use double backslash (\\) or put an r before your string to escape special sequences such as \n or \t. – Marcelo Villa Jun 06 '19 at 15:31