Merging features in feature class with arcpy

6881
6
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 Alum

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

6 Replies
Jeremy_Moore
MVP Alum

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 Alum

You're very welcome

0 Kudos
JTBatSLO
New Contributor

Greetings Jeremy,

As best I can tell, the arcpy.Merge_Management() gp tool does not function the same as the "esri_editing_MergeFeatures" tool available from the ribbon, in that the gp tool will not permit features to be merged within the originating feature class.

Is there any way to Merge features as one might do from the Modify Features pane in ArcGIS Pro, but 
programmatically from a stand-alone Python script?

mgeguner
New Contributor

were you able to do this

0 Kudos
wolfvincent
New Contributor III

Same question here ^^

0 Kudos