[937] Combine different shapefiles and remove duplicate features

发布时间 2023-11-15 14:02:58作者: McDelfino

In arcpy, you can combine different shapefiles and remove duplicate features using the arcpy.management.Merge tool and the arcpy.management.DeleteIdentical tool. Here's an example:

import arcpy

# Set the workspace environment
arcpy.env.workspace = r'C:\Path\To\Your\Workspace.gdb'

# List of shapefiles to combine
shapefiles_to_combine = ['Shapefile1', 'Shapefile2', 'Shapefile3']

# Output shapefile with combined features
output_shapefile = 'CombinedShapefile'

# Merge the shapefiles into a new shapefile
arcpy.management.Merge(shapefiles_to_combine, output_shapefile)

# Remove duplicate features based on geometry
arcpy.management.DeleteIdentical(output_shapefile, "SHAPE")

print(f'Shapefiles combined and duplicate features removed in {output_shapefile}.')

Replace 'C:\Path\To\Your\Workspace.gdb' with the actual path to your geodatabase, 'Shapefile1', 'Shapefile2', 'Shapefile3' with the names of the shapefiles you want to combine, and 'CombinedShapefile' with the desired name for the new shapefile.

In this example, the Merge tool is used to combine the specified shapefiles into a new shapefile, and then the DeleteIdentical tool is used to remove duplicate features based on geometry. Adjust the list of shapefiles and the output shapefile name based on your specific requirements. Note that the DeleteIdentical tool removes features that have identical geometries; if you want to remove duplicates based on attributes, you can specify the attribute fields in the second parameter of the tool.