<?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: Creating A New Feature Class From List Output in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/creating-a-new-feature-class-from-list-output/m-p/341742#M26793</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a bit of python code that compares consecutive row values in a field. If the first feature's field value is 1 and the second feature's field value is 2, it prints "Different." If they are both 1, it prints "Same." I want to take the features that read "Different" and shoot those out to a new feature class. I know there's a way to do this in python, but I can't seem to come up with it. My list script is as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;IdList[]
rows = arcpy.SearchCursor("INPUT FEATURE CLASS")

for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IdPlusOne = int(row.FIELD) + int(1)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IdList.append(IdPlusOne)

del row, rows

i = 0
i1 = 1

for Id in IdList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if i1 &amp;gt;= len(IdList):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif Id == IdList[i1]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Same")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i+=1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i1+=1

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Different")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i+=1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i1+=1&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So I would just like to have those rows that get listed as "Different" to be exported to a new feature class. Is this doable? Thanks so much for any assistance.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Tommy Burk&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 16:08:10 GMT</pubDate>
    <dc:creator>TommyBurk</dc:creator>
    <dc:date>2021-12-11T16:08:10Z</dc:date>
    <item>
      <title>Creating A New Feature Class From List Output</title>
      <link>https://community.esri.com/t5/python-questions/creating-a-new-feature-class-from-list-output/m-p/341741#M26792</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a bit of python code that compares consecutive row values in a field. If the first feature's field value is 1 and the second feature's field value is 2, it prints "Different." If they are both 1, it prints "Same." I want to take the features that read "Different" and shoot those out to a new feature class. I know there's a way to do this in python, but I can't seem to come up with it. My list script is as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&lt;/PRE&gt;&lt;SPAN&gt;IdList[]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;rows = arcpy.SearchCursor("INPUT FEATURE CLASS")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;for row in rows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IdPlusOne = int(row.FIELD) + int(1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IdList.append(IdPlusOne)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;del row, rows&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;i = 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;i1 = 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;for Id in IdList:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if i1 &amp;gt;= len(IdList):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif Id == IdList[i1]:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Same")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i+=1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i1+=1&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Different")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i+=1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i1+=1&lt;/SPAN&gt;&lt;PRE class="plain" name="code"&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So I would just like to have those rows that get listed as "Different" to be exported to a new feature class. Is this doable? Thanks so much for any assistance.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Tommy Burk&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Jan 2012 09:56:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-a-new-feature-class-from-list-output/m-p/341741#M26792</guid>
      <dc:creator>TommyBurk</dc:creator>
      <dc:date>2012-01-31T09:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: Creating A New Feature Class From List Output</title>
      <link>https://community.esri.com/t5/python-questions/creating-a-new-feature-class-from-list-output/m-p/341742#M26793</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a bit of python code that compares consecutive row values in a field. If the first feature's field value is 1 and the second feature's field value is 2, it prints "Different." If they are both 1, it prints "Same." I want to take the features that read "Different" and shoot those out to a new feature class. I know there's a way to do this in python, but I can't seem to come up with it. My list script is as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;IdList[]
rows = arcpy.SearchCursor("INPUT FEATURE CLASS")

for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IdPlusOne = int(row.FIELD) + int(1)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IdList.append(IdPlusOne)

del row, rows

i = 0
i1 = 1

for Id in IdList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if i1 &amp;gt;= len(IdList):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif Id == IdList[i1]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Same")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i+=1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i1+=1

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Different")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i+=1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i1+=1&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So I would just like to have those rows that get listed as "Different" to be exported to a new feature class. Is this doable? Thanks so much for any assistance.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Tommy Burk&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:08:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-a-new-feature-class-from-list-output/m-p/341742#M26793</guid>
      <dc:creator>TommyBurk</dc:creator>
      <dc:date>2021-12-11T16:08:10Z</dc:date>
    </item>
    <item>
      <title>Re: Creating A New Feature Class From List Output</title>
      <link>https://community.esri.com/t5/python-questions/creating-a-new-feature-class-from-list-output/m-p/341743#M26794</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;you could add a flag item to the table, and in addition to printing 'different' you would update the flag to an appropriate value (say, 1). You would need to use an Update Cursor instead of a Search Cursor, of course. After setting the flag, just export the rows with the flag = 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Then drop the flag item&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;OR&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;keep the search cursor, but when you find a 'different' row, capture all the attributes (including the Shape) for that record to a python list.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;append that list to a master list, so you build a list of lists of records.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;you will also build a similar list of the table items, types, and widths, appended to a master list for the table&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Create a new feature class, with the same table schema (use the table items list to add items)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;feed the master records list to an Insert Cursor, breaking out each item value (and the shape itself) from the nested list.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Jan 2012 11:02:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-a-new-feature-class-from-list-output/m-p/341743#M26794</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2012-01-31T11:02:53Z</dc:date>
    </item>
    <item>
      <title>Re: Creating A New Feature Class From List Output</title>
      <link>https://community.esri.com/t5/python-questions/creating-a-new-feature-class-from-list-output/m-p/341744#M26795</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;i´d go with mark´s 1st suggestion.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;exchange the search cursor for an update cursor and fill a field so you can differentiate between features to export/not export.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;then you could use feature class to feature class with a SQL query on the new field (choose records where flag=1) . description of it can be found there:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001200000020000000"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001200000020000000&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Jan 2012 11:24:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-a-new-feature-class-from-list-output/m-p/341744#M26795</guid>
      <dc:creator>RaphaelR</dc:creator>
      <dc:date>2012-01-31T11:24:51Z</dc:date>
    </item>
    <item>
      <title>Re: Creating A New Feature Class From List Output</title>
      <link>https://community.esri.com/t5/python-questions/creating-a-new-feature-class-from-list-output/m-p/341745#M26796</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Mark,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is great. It's exactly what I want to do. I am unfamiliar with how to add/drop a flag item to/from the table. Can you give me a quick example of how that works? Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Tommy Burk&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Jan 2012 12:31:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-a-new-feature-class-from-list-output/m-p/341745#M26796</guid>
      <dc:creator>TommyBurk</dc:creator>
      <dc:date>2012-01-31T12:31:24Z</dc:date>
    </item>
    <item>
      <title>Re: Creating A New Feature Class From List Output</title>
      <link>https://community.esri.com/t5/python-questions/creating-a-new-feature-class-from-list-output/m-p/341746#M26797</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If I understand your problem correctly, you want to identify all of the features that have an attribute different than the previous feature, and put those in a new featureclass. I'm still using 9.2, so some of the syntax and capitalization might need correcting, but this should accomplish what you need:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;inFile = "INPUT FEATURE CLASS" selectionLayer = MakeFeatureLayer("inFile") rows = arcpy.SearchCursor(inFile) last = "" #or maybe 0 if the attribute is an integer instead of a string for row in rows: &amp;nbsp;&amp;nbsp;&amp;nbsp; if row.FIELD != last: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Different") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute(selectionLayer, "ADD_TO_SELECTION", "\"FID\" = '%s'" % row.FID) #FID is some unique identifier for each feature &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #change the where clause to "\"FID\" = %i" if FID is an integer &amp;nbsp;&amp;nbsp;&amp;nbsp; else &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Same") &amp;nbsp;&amp;nbsp;&amp;nbsp; last = row.FIELD arcpy.CopyFeatures(selectionLayer, "OUTPUT FEATURE CLASS")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Jan 2012 12:39:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-a-new-feature-class-from-list-output/m-p/341746#M26797</guid>
      <dc:creator>BruceNielsen</dc:creator>
      <dc:date>2012-01-31T12:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: Creating A New Feature Class From List Output</title>
      <link>https://community.esri.com/t5/python-questions/creating-a-new-feature-class-from-list-output/m-p/341747#M26798</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Bruce,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That did exactly what I needed. Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Tommy Burk&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Jan 2012 13:17:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-a-new-feature-class-from-list-output/m-p/341747#M26798</guid>
      <dc:creator>TommyBurk</dc:creator>
      <dc:date>2012-01-31T13:17:00Z</dc:date>
    </item>
    <item>
      <title>Re: Creating A New Feature Class From List Output</title>
      <link>https://community.esri.com/t5/python-questions/creating-a-new-feature-class-from-list-output/m-p/341748#M26799</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Bruce's add to selection loop is one way of doing it, and should work fine, but sometimes if you have a lot of add-to-selections it gets unweildy.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I prefer simpler selections, saved in attibutes or lists, over Bruce's way, but to each his own.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My first suggestion was very simple: use add item to add the flag item (for exampe: FLAG as short_integer), and every time you find the 'different' record, set FLAG = 1 with the Update Cursor.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;afterwards, select all the FLAG = 1 records and export &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Some people don't like adding temporary items to their tables, which is why I suggested an alternitive.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Jan 2012 17:54:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-a-new-feature-class-from-list-output/m-p/341748#M26799</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2012-01-31T17:54:10Z</dc:date>
    </item>
  </channel>
</rss>

