<?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 Re: Merge multiple features in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/merge-multiple-features/m-p/565583#M44280</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I should have clarified that you only need the &lt;SPAN style="font-family: 'courier new', courier;"&gt;arcpy.ClearWorkspaceCache_management()&lt;/SPAN&gt; at the end if you're making an SDE connection. so if you're in a personal or file geodatabase you can get rid of that line.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 10 Feb 2015 21:55:49 GMT</pubDate>
    <dc:creator>BlakeTerhune</dc:creator>
    <dc:date>2015-02-10T21:55:49Z</dc:date>
    <item>
      <title>Merge multiple features</title>
      <link>https://community.esri.com/t5/python-questions/merge-multiple-features/m-p/565577#M44274</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Good day,&lt;/P&gt;&lt;P&gt;I have a GDB with features with almost the same name only the last postfix is a underscore and a number (Test_area,&amp;nbsp; Test_area_1)&lt;/P&gt;&lt;P&gt;I am working an a script that will merge the features with the same name. This is what i have so far:&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;It works but the feature list is about 50 features long and more important I would like to learn how I can improve this script.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy import env
import os

# Set the workspace for the ListFeatureClass function
&lt;OL style="list-style-type: lower-alpha;"&gt;&lt;LI&gt;arcpy.env.workspace = r"D:\ GIS \Test.gdb"&lt;/LI&gt;&lt;/OL&gt;
outputA = r" D:\ GIS \Output.gdb \ TestA_area "
outputB = r" D:\ GIS \ Output.gdb \ TestB_area "
outputC = r" D:\ GIS \ Output.gdb \ TestC_area "
outputD = r" D:\ GIS \ Output.gdb \ TestD_area "

# Use the ListFeatureClasses function to return a list of all FC.
fclistA = arcpy.ListFeatureClasses("TestA_area*","ALL")
fclistB = arcpy.ListFeatureClasses("TestB_area*","ALL")
fclistC = arcpy.ListFeatureClasses("TestC_area*","ALL")
fclistD = arcpy.ListFeatureClasses("TestD_area*","ALL")
&lt;OL style="list-style-type: lower-alpha;"&gt;&lt;LI&gt;arcpy.Merge_management(fclistA, outputA)&lt;/LI&gt;&lt;LI&gt;arcpy.Merge_management(fclistB, outputB)&lt;/LI&gt;&lt;LI&gt;arcpy.Merge_management(fclistC, outputC)&lt;/LI&gt;&lt;LI&gt;arcpy.Merge_management(fclistD, outputD)&lt;/LI&gt;&lt;/OL&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;greeting peter&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:22:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/merge-multiple-features/m-p/565577#M44274</guid>
      <dc:creator>PeterVersteeg</dc:creator>
      <dc:date>2021-12-12T00:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: Merge multiple features</title>
      <link>https://community.esri.com/t5/python-questions/merge-multiple-features/m-p/565578#M44275</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why dont' you get a &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/ListFeatureClasses/03q300000023000000/"&gt;list of featureclasses &lt;/A&gt;first specifying an appropriate wildcard, then perform the merge within a loop (probably)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Feb 2015 19:00:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/merge-multiple-features/m-p/565578#M44275</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-02-03T19:00:24Z</dc:date>
    </item>
    <item>
      <title>Re: Merge multiple features</title>
      <link>https://community.esri.com/t5/python-questions/merge-multiple-features/m-p/565579#M44276</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In your example you only have four feature classes with different prefixe variations (A, B, C, and D). Are those four prefixes always fixed or could they change? If there are more than just those four or if they change, please describe the formatting and/or range of the possible prefixes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, I noticed some inconsistencies with your imports:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;If you import arcpy (like you do on the first line), it includes env. It is redundant to have from arcpy import env if you've already imported everything in arcpy; especially if you're still calling workspace with the full arcpy.env.workspace&lt;/LI&gt;&lt;LI&gt;You import os but I don't see that you're using it anywhere. Might save a little time to just not import it if you're not using it.&lt;/LI&gt;&lt;/UL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Feb 2015 20:44:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/merge-multiple-features/m-p/565579#M44276</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-02-03T20:44:48Z</dc:date>
    </item>
    <item>
      <title>Re: Merge multiple features</title>
      <link>https://community.esri.com/t5/python-questions/merge-multiple-features/m-p/565580#M44277</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN lang="EN-GB" style="font-size: 10.5pt; font-family: Helvetica, sans-serif;"&gt;thank you for your response and your remark on my inconsistencies.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-GB" style="font-size: 10.5pt; font-family: Helvetica, sans-serif;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-GB" style="font-size: 10.5pt; font-family: Helvetica, sans-serif;"&gt; the feature class list is about 100 lines long and the TestA_area* etc. the names are always the same.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-GB" style="font-size: 10.5pt; font-family: Helvetica, sans-serif;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-GB" style="font-size: 10.5pt; font-family: Helvetica, sans-serif;"&gt;what I was thinking is it possible to make the script look at the first 10 characters and put those features in a list without setting the wildcard (TestA_area*). So all features in a list who's first 10 characters are the same. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-GB" style="font-size: 10.5pt; font-family: Helvetica, sans-serif;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-GB" style="font-size: 10.5pt; font-family: Helvetica, sans-serif;"&gt;greetings peter&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Feb 2015 14:52:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/merge-multiple-features/m-p/565580#M44277</guid>
      <dc:creator>PeterVersteeg</dc:creator>
      <dc:date>2015-02-04T14:52:30Z</dc:date>
    </item>
    <item>
      <title>Re: Merge multiple features</title>
      <link>https://community.esri.com/t5/python-questions/merge-multiple-features/m-p/565581#M44278</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Does something like this get you what you need?&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def main():
&amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy
&amp;nbsp;&amp;nbsp;&amp;nbsp; import os

&amp;nbsp;&amp;nbsp;&amp;nbsp; inputgdb = r"C:\temp\input.gdb"
&amp;nbsp;&amp;nbsp;&amp;nbsp; outputgdb = r"C:\temp\output.gdb"
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = inputgdb

&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in ["A", "B", "C", "D"]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; wild_card = "Test{}_area*".format(i)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fclist = arcpy.ListFeatureClasses(wild_card)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outputfc = os.path.join(outputgdb, "Test{}_area".format(i))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Merge_management(fclist, outputfc)

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.ClearWorkspaceCache_management()&amp;nbsp; ## Cleanup


if __name__ == '__main__':
&amp;nbsp;&amp;nbsp;&amp;nbsp; main()&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This assumes you do not have any feature classes in a feature dataset. If you do, the code will be slightly different.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:22:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/merge-multiple-features/m-p/565581#M44278</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-12-12T00:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: Merge multiple features</title>
      <link>https://community.esri.com/t5/python-questions/merge-multiple-features/m-p/565582#M44279</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Because the names are a bit different then in my example I had to do same minor adjustments. I had same trouble getting the right outputname but it works now. I think one could get the outputname in a cleaner way but I am still learning and am very happy it works.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks Blake for the help&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def main():&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; import os&amp;nbsp; 
&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; inputgdb = r"Y:\Duitsland\GUTZ\Duitsland_GUTZ_N52_OLD2.gdb"&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; outputgdb = r"Y:\Duitsland\GUTZ\outputTest.gdb"&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = inputgdb&amp;nbsp; 
&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in ["A_AA010", "A_AA514", "A_AB000", "A_AB030"]:&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; wild_card = "{}_*".format(i)&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fclist = arcpy.ListFeatureClasses(wild_card)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fcname = fclist[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fcOutputName = "{}".format(i) + fcname[7:]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outputfc = os.path.join(outputgdb, fcOutputName)&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Merge_management(fclist, outputfc)


arcpy.ClearWorkspaceCache_management()&amp;nbsp; ## Cleanup&amp;nbsp; 
&amp;nbsp; 
&amp;nbsp; 
if __name__ == '__main__':&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; main()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:22:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/merge-multiple-features/m-p/565582#M44279</guid>
      <dc:creator>PeterVersteeg</dc:creator>
      <dc:date>2021-12-12T00:22:18Z</dc:date>
    </item>
    <item>
      <title>Re: Merge multiple features</title>
      <link>https://community.esri.com/t5/python-questions/merge-multiple-features/m-p/565583#M44280</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I should have clarified that you only need the &lt;SPAN style="font-family: 'courier new', courier;"&gt;arcpy.ClearWorkspaceCache_management()&lt;/SPAN&gt; at the end if you're making an SDE connection. so if you're in a personal or file geodatabase you can get rid of that line.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Feb 2015 21:55:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/merge-multiple-features/m-p/565583#M44280</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-02-10T21:55:49Z</dc:date>
    </item>
  </channel>
</rss>

