<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Merging/dissolving all features within feature classes in geodatabase using ArcPy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/merging-dissolving-all-features-within-feature/m-p/1005452#M59165</link>
    <description>&lt;DIV class="votecell post-layout--left"&gt;&lt;DIV class="js-voting-container grid jc-center fd-column ai-stretch gs4 fc-black-200"&gt;&lt;SPAN&gt;I have a geodatabase with multiple feature classes. In each feature class there are multiple features. I would like to merge/dissolve them so there is only one feature per feature class (keeping the same output location)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="postcell post-layout--right"&gt;&lt;DIV class="s-prose js-post-body"&gt;&lt;P&gt;Can someone provide an example of a a script that would loop through each feature class within the gdb and perform the process below.&lt;/P&gt;&lt;P&gt;Manual method: Edit &amp;gt; Select All &amp;gt; Merge &amp;gt; Save/Stop Edit&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;I have attached an image of the gdb with feature classes that i want to loop through.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Mon, 30 Nov 2020 10:57:33 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2020-11-30T10:57:33Z</dc:date>
    <item>
      <title>Merging/dissolving all features within feature classes in geodatabase using ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/merging-dissolving-all-features-within-feature/m-p/1005452#M59165</link>
      <description>&lt;DIV class="votecell post-layout--left"&gt;&lt;DIV class="js-voting-container grid jc-center fd-column ai-stretch gs4 fc-black-200"&gt;&lt;SPAN&gt;I have a geodatabase with multiple feature classes. In each feature class there are multiple features. I would like to merge/dissolve them so there is only one feature per feature class (keeping the same output location)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="postcell post-layout--right"&gt;&lt;DIV class="s-prose js-post-body"&gt;&lt;P&gt;Can someone provide an example of a a script that would loop through each feature class within the gdb and perform the process below.&lt;/P&gt;&lt;P&gt;Manual method: Edit &amp;gt; Select All &amp;gt; Merge &amp;gt; Save/Stop Edit&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;I have attached an image of the gdb with feature classes that i want to loop through.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 30 Nov 2020 10:57:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/merging-dissolving-all-features-within-feature/m-p/1005452#M59165</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2020-11-30T10:57:33Z</dc:date>
    </item>
    <item>
      <title>Re: Merging/dissolving all features within feature classes in geodatabase using ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/merging-dissolving-all-features-within-feature/m-p/1005464#M59167</link>
      <description>&lt;P&gt;merge and dissolve are different processes, with the latter removing shared boundaries in polygons as in the "bird on dog" images below.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dissolve_sq2_0.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/1169i10353DE17ECB54DA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dissolve_sq2_0.png" alt="dissolve_sq2_0.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dissolve_sq2_1.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/1170i893D31B955E7D4CC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dissolve_sq2_1.png" alt="dissolve_sq2_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;yes it can be done, but your image doesn't open&lt;/P&gt;</description>
      <pubDate>Mon, 30 Nov 2020 11:48:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/merging-dissolving-all-features-within-feature/m-p/1005464#M59167</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2020-11-30T11:48:30Z</dc:date>
    </item>
    <item>
      <title>Re: Merging/dissolving all features within feature classes in geodatabase using ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/merging-dissolving-all-features-within-feature/m-p/1005465#M59168</link>
      <description>&lt;P&gt;Thanks for your response. Im not sure why it doesnt, ill try re uploading. In the meantime dissolve would be the preferred option so theres on "multipart" polygon.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Nov 2020 11:57:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/merging-dissolving-all-features-within-feature/m-p/1005465#M59168</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2020-11-30T11:57:15Z</dc:date>
    </item>
    <item>
      <title>Re: Merging/dissolving all features within feature classes in geodatabase using ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/merging-dissolving-all-features-within-feature/m-p/1005469#M59169</link>
      <description>&lt;P&gt;To dissolve in arcmap/pro, you need a common attribute to dissolve on.&amp;nbsp; You could add a field with a common value if you don't have one, first and use it as the dissolve field.&amp;nbsp; You then follow this up with a union to produce a multipart polygon.&lt;/P&gt;&lt;P&gt;The example I have shown is for my own geometry constructor which does it without those requirements.&amp;nbsp; I will blog about it soon when I am done testing and it will be available then.&amp;nbsp; In the interim, use the process as describe above&lt;/P&gt;</description>
      <pubDate>Mon, 30 Nov 2020 12:15:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/merging-dissolving-all-features-within-feature/m-p/1005469#M59169</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2020-11-30T12:15:05Z</dc:date>
    </item>
    <item>
      <title>Re: Merging/dissolving all features within feature classes in geodatabase using ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/merging-dissolving-all-features-within-feature/m-p/1005470#M59170</link>
      <description>&lt;P&gt;Hi, I think you can approach it with the '&lt;A href="https://pro.arcgis.com/en/pro-app/tool-reference/data-management/dissolve.htm" target="_blank" rel="noopener"&gt;Dissolve&lt;/A&gt;' tool which is also exposed as a python function.&lt;/P&gt;&lt;P&gt;You could go with more fine-grained manipulations through the arcpy.Geometry class and it's respective methods but it might be overkill for now.&lt;/P&gt;&lt;P&gt;Bearing in mind that the output will be a new featureclass, you can choose to output to an 'in-memory' or 'physical' featureclass in the fGDB - choosing to write the in-memory featureclass to the fGDB later.&lt;/P&gt;&lt;P&gt;1. set your file GDB as the workspace with:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.env.workspace = //path/to/Test.gdb&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(replace the full path to your Test.gdb above).&lt;/P&gt;&lt;P&gt;2. Next you would need to loop through each featureclass in your fGDB, but first &lt;A href="https://pro.arcgis.com/en/pro-app/arcpy/functions/listfeatureclasses.htm" target="_blank" rel="noopener"&gt;list all featureclasses&lt;/A&gt; inside it.&lt;/P&gt;&lt;P&gt;3. Dissolve on each featureclass and choose to dissolve on a particular field or leave the default. (ensure you leave the parameter 'MULTI_PART' so that a multipart feature is written).&lt;/P&gt;&lt;P&gt;4. Keep a reference to the original featureclass (restore it later)&lt;/P&gt;&lt;P&gt;5. delete the original featureclass&lt;/P&gt;&lt;P&gt;6. Rename the dissolved feature class back to your original.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, together:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import sys

fileGDB = "C:\\path\\to\\test.gdb"

arcpy.env.workspace = fileGDB

featureclasses = arcpy.ListFeatureClasses()


for fc in featureclasses:
    original_featureclass = fc
    dissolved_featureclass = fc + '_dissolved'
    try:
        print("original featureclass: {0}".format(original_featureclass))
        arcpy.management.Dissolve(fc, dissolved_featureclass, None, None, "MULTI_PART", "DISSOLVE_LINES")
        print("dissolved featureclass: {0}".format(dissolved_featureclass))
    except Exception:
        e = sys.exc_info()[1]
        print(e.args[0])
        
    try:
        arcpy.Delete_management(fc)
        print("original featureclass deleted: {0}".format(fc))
    except Exception:
        e = sys.exc_info()[1]
        print(e.args[0])
        
    try:
        
        arcpy.Rename_management(dissolved_featureclass, original_featureclass)
        print("original featureclass restored: {0}".format(original_featureclass))
    except Exception:
        e = sys.exc_info()[1]
        print(e.args[0])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best.&lt;/P&gt;&lt;P&gt;------&lt;/P&gt;&lt;P&gt;Edit: after I returned to this I saw Dan's post and yes, you need to dissolve on an attribute.&lt;/P&gt;&lt;P&gt;I'm not sure what it dissolves on if you leave the dissolve field blank - probably the geometries.&lt;/P&gt;&lt;P&gt;It would be worthwhile getting to know the nuances in the arcpy.Geometry class.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Nov 2020 12:44:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/merging-dissolving-all-features-within-feature/m-p/1005470#M59170</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2020-11-30T12:44:15Z</dc:date>
    </item>
    <item>
      <title>Re: Merging/dissolving all features within feature classes in geodatabase using ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/merging-dissolving-all-features-within-feature/m-p/1005486#M59171</link>
      <description>&lt;P&gt;Thank you Dan and David,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The script does it. I just need to tweak it a little.&lt;BR /&gt;&lt;BR /&gt;Very much appreciated.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Nov 2020 13:23:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/merging-dissolving-all-features-within-feature/m-p/1005486#M59171</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2020-11-30T13:23:07Z</dc:date>
    </item>
    <item>
      <title>Re: Merging/dissolving all features within feature classes in geodatabase using ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/merging-dissolving-all-features-within-feature/m-p/1263043#M66976</link>
      <description>&lt;P&gt;Hi, I am working on a similar script and can answer your comment: "&lt;SPAN&gt;I'm not sure what it dissolves on if you leave the dissolve field blank - probably the geometries."&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I assume that leaving the dissolve field blank does dissolve on the geometry--I just tested it and the output gave me one multipart feature. If you add statistics fields while leaving the dissolve field blank, it will also calculate those for the single output feature. I figured I'd share since it's&amp;nbsp;quicker/simpler to leave the field blank than add and calculate a new field (and potentially need to delete it afterwards) to dissolve all--that's what I used to do and have seen others suggest in this forum since I don't think it's completely obvious that leaving the dissolve field blank will accomplish the same thing.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 14:58:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/merging-dissolving-all-features-within-feature/m-p/1263043#M66976</guid>
      <dc:creator>NSamu</dc:creator>
      <dc:date>2023-03-01T14:58:55Z</dc:date>
    </item>
  </channel>
</rss>

