Merging features in feature class with arcpy

2741
3
Jump to solution
09-18-2019 11:49 AM
ThomasBlankinship
New Contributor

I need to merge all polygon features in a given feature class into a single polygon. The intended functionality is similar to the "Merge" tool under the Edit->Tools tab. The Merge_management tool takes feature classes as an input and I cannot find documentation on the difference/command for this "Edit->Merge." 

I figure I will have to iterate through my feature class using a search cursor and use the dissolve tool to merge the features. I have tried iterations of the following to no avail:

with ap.da.SearchCursor(feature_class, "*") as cursor:
    feature_list = []
    for row in cursor:
        feature_list.append(row)
    ap.Dissolve_management(feature_list, out_feature_class, {dissolve_field},{statistics_fields}, {multi_part}, {unsplit_lines})‍‍‍‍‍‍‍‍

My question is what do I use as my in_features (first field in ap.Dissolve_management)? How do I pass the features into the ap.Dissolve_management function?

0 Kudos
1 Solution

Accepted Solutions
Jeremy_Moore
MVP

In ArcGIS Pro you can access the Merge tool from the edit ribbon and Merge will be under the tools section. 

You can also access the merge tool in arcpy from arcpy.Merge_Management() and the documentation can be found here :https://pro.arcgis.com/en/pro-app/tool-reference/data-management/merge.htm

If this is a one off process and not being incorporated into a automated workflow it would probably be easier just to do it in ArcGIS Pro.

If you still want to do it within python let us know. I can give you a hand with the dissolve tool or the merge tool. Which ever fits the bill

EDIT:

From the documentation it looks like you do not have to iterate through a feature inside of a feature class to get dissolve to work. It's documentation is here:

https://pro.arcgis.com/en/pro-app/tool-reference/data-management/dissolve.htm

So your code should look something like this:

import arcpy as ap

ap.env.workspace = r"Path To Your Featureclass"
feature_name = "The name of the feature to dissolve all polygons into one"

ap.Dissolve_management(feature_name, out_feature_class, {dissolve_field}, {statistics_fields}, {multi_part}, {unsplit_lines})‍‍‍‍‍‍

View solution in original post

3 Replies
Jeremy_Moore
MVP

In ArcGIS Pro you can access the Merge tool from the edit ribbon and Merge will be under the tools section. 

You can also access the merge tool in arcpy from arcpy.Merge_Management() and the documentation can be found here :https://pro.arcgis.com/en/pro-app/tool-reference/data-management/merge.htm

If this is a one off process and not being incorporated into a automated workflow it would probably be easier just to do it in ArcGIS Pro.

If you still want to do it within python let us know. I can give you a hand with the dissolve tool or the merge tool. Which ever fits the bill

EDIT:

From the documentation it looks like you do not have to iterate through a feature inside of a feature class to get dissolve to work. It's documentation is here:

https://pro.arcgis.com/en/pro-app/tool-reference/data-management/dissolve.htm

So your code should look something like this:

import arcpy as ap

ap.env.workspace = r"Path To Your Featureclass"
feature_name = "The name of the feature to dissolve all polygons into one"

ap.Dissolve_management(feature_name, out_feature_class, {dissolve_field}, {statistics_fields}, {multi_part}, {unsplit_lines})‍‍‍‍‍‍
ThomasBlankinship
New Contributor

Thank you a ton! The documentation confused me, but that works exactly as I wanted.

0 Kudos
Jeremy_Moore
MVP

You're very welcome

0 Kudos