<?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: Editing shapefile with Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/editing-shapefile-with-python/m-p/608289#M47478</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
from arcpy import env

env.workspace = #"put the file path to the folder your shapefile is in here as a string"

cursor =&amp;nbsp; arcpy.da.UpdateCursor(#"shapefile name" , "Field name that has the 1's and 0's")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if row[0] == 1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.deleteRow()

del row 
del cursor

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;I'd make a copy of your shapefile first to test this on, there is no way to undo the delete row, so I would test it on the copy before applying it to the actual file.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Ok...I'll try. Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 02:02:30 GMT</pubDate>
    <dc:creator>João_PauloPereira</dc:creator>
    <dc:date>2021-12-12T02:02:30Z</dc:date>
    <item>
      <title>Editing shapefile with Python</title>
      <link>https://community.esri.com/t5/python-questions/editing-shapefile-with-python/m-p/608285#M47474</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm new here at the Forum and I tried looking for something like my problem, and I got nothing. If there is something, please, forgive me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a binary polygon shapefile, with a feature called GRIDCODE with 0s and 1s for earch polygon.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to edit this shapefile and delete every polygon with the number 1. In other words, I want only the polygons with GRIDCODE number 0 in my shapefile. To do that in Editor mode is quite simple, but I want to do it through a python code. Does anymore here know how to do it?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Apr 2014 12:52:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/editing-shapefile-with-python/m-p/608285#M47474</guid>
      <dc:creator>João_PauloPereira</dc:creator>
      <dc:date>2014-04-11T12:52:32Z</dc:date>
    </item>
    <item>
      <title>Re: Editing shapefile with Python</title>
      <link>https://community.esri.com/t5/python-questions/editing-shapefile-with-python/m-p/608286#M47475</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'd probably use an update cursor to evaluate the value of the field, then delete the row if it the field value equals 1.&amp;nbsp; If you need some starter code let me know.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Apr 2014 13:01:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/editing-shapefile-with-python/m-p/608286#M47475</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2014-04-11T13:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: Editing shapefile with Python</title>
      <link>https://community.esri.com/t5/python-questions/editing-shapefile-with-python/m-p/608287#M47476</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I'd probably use an update cursor to evaluate the value of the field, then delete the row if it the field value equals 1.&amp;nbsp; If you need some starter code let me know.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;iamurray, thanks for the help. If you could send me the code I would appreciate. I'm new using python in ArcGIS, so every help is welcome.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Apr 2014 17:00:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/editing-shapefile-with-python/m-p/608287#M47476</guid>
      <dc:creator>João_PauloPereira</dc:creator>
      <dc:date>2014-04-11T17:00:33Z</dc:date>
    </item>
    <item>
      <title>Re: Editing shapefile with Python</title>
      <link>https://community.esri.com/t5/python-questions/editing-shapefile-with-python/m-p/608288#M47477</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
from arcpy import env

env.workspace = #"put the file path to the folder your shapefile is in here as a string"

cursor =&amp;nbsp; arcpy.da.UpdateCursor(#"shapefile name" , "Field name that has the 1's and 0's")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if row[0] == 1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.deleteRow()

del row 
del cursor

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'd make a copy of your shapefile first to test this on, there is no way to undo the delete row, so I would test it on the copy before applying it to the actual file.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:02:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/editing-shapefile-with-python/m-p/608288#M47477</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2021-12-12T02:02:27Z</dc:date>
    </item>
    <item>
      <title>Re: Editing shapefile with Python</title>
      <link>https://community.esri.com/t5/python-questions/editing-shapefile-with-python/m-p/608289#M47478</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
from arcpy import env

env.workspace = #"put the file path to the folder your shapefile is in here as a string"

cursor =&amp;nbsp; arcpy.da.UpdateCursor(#"shapefile name" , "Field name that has the 1's and 0's")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if row[0] == 1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.deleteRow()

del row 
del cursor

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;I'd make a copy of your shapefile first to test this on, there is no way to undo the delete row, so I would test it on the copy before applying it to the actual file.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Ok...I'll try. Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:02:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/editing-shapefile-with-python/m-p/608289#M47478</guid>
      <dc:creator>João_PauloPereira</dc:creator>
      <dc:date>2021-12-12T02:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: Editing shapefile with Python</title>
      <link>https://community.esri.com/t5/python-questions/editing-shapefile-with-python/m-p/608290#M47479</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Use arcpy.SelectLayerByAttribute_management then arcpy.DeleteFeatures_management&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Code examples are in the help:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;A class="jive-link-external-small" href="http://resources.arcgis.com/en/help/main/10.2/index.html#//001700000071000000" rel="nofollow" target="_blank"&gt;http://resources.arcgis.com/en/help/main/10.2/index.html#//001700000071000000&lt;/A&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;A class="jive-link-external-small" href="http://resources.arcgis.com/en/help/main/10.2/index.html#//001700000036000000" rel="nofollow" target="_blank"&gt;http://resources.arcgis.com/en/help/main/10.2/index.html#//001700000036000000&lt;/A&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 13 Apr 2014 10:24:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/editing-shapefile-with-python/m-p/608290#M47479</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2014-04-13T10:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: Editing shapefile with Python</title>
      <link>https://community.esri.com/t5/python-questions/editing-shapefile-with-python/m-p/608291#M47480</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Use arcpy.SelectLayerByAttribute_management then arcpy.DeleteFeatures_management&lt;BR /&gt;&lt;BR /&gt;Code examples are in the help:&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//001700000071000000"&gt;http://resources.arcgis.com/en/help/main/10.2/index.html#//001700000071000000&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//001700000036000000"&gt;http://resources.arcgis.com/en/help/main/10.2/index.html#//001700000036000000&lt;/A&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the answer again Ipinner...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Your tip worked perfectly. The code turned like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management ("GAP", "NEW_SELECTION", " GRIDCODE=1 ")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.DeleteFeatures_management("GAP")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Quite easy and everything worked really nice...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Apr 2014 10:41:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/editing-shapefile-with-python/m-p/608291#M47480</guid>
      <dc:creator>João_PauloPereira</dc:creator>
      <dc:date>2014-04-17T10:41:28Z</dc:date>
    </item>
  </channel>
</rss>

