[937] Combine different shapefiles and remove duplicate features
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.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
2019-11-15 【451】python 同一行打印进度条