<?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 shapefiles with Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/editing-shapefiles-with-python/m-p/257019#M19772</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try changing your expression variable to:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;expression = "round(!WSPD_SFC!/5.0, 0) * 5.0"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Since the expression is quoted as a string, it will not read 'input' as a variable.&amp;nbsp; It will read this as a string literal.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 02 Apr 2012 11:01:13 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2012-04-02T11:01:13Z</dc:date>
    <item>
      <title>Editing shapefiles with Python</title>
      <link>https://community.esri.com/t5/python-questions/editing-shapefiles-with-python/m-p/257016#M19769</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello folks.&amp;nbsp; I had a post over on the general forum about how to round values using the field calculator.&amp;nbsp; I got the answer I was looking for but was referred to this board to ask a question about python.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have to edit a series of shapefiles (about 100).&amp;nbsp; They all have the same field labels.&amp;nbsp; I need to add a field, and then round a certain field we will call "X", to the nearest five, and populate the new field with those values.&amp;nbsp; The formula I was given was&amp;nbsp; "Round(&lt;X&gt;/5.0, 0) * 5.0".&amp;nbsp; I have a some experience working with arcpy and python, however I have never used it to modify a shapefile.&amp;nbsp; Can someone help me out with the script I would use to do what I have described above so i can then write it into a loop and do the work on all my shapefiles.&amp;nbsp; I can handle the loop part.&amp;nbsp; Thanks!&lt;/X&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 01 Apr 2012 10:17:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/editing-shapefiles-with-python/m-p/257016#M19769</guid>
      <dc:creator>CharlesGant</dc:creator>
      <dc:date>2012-04-01T10:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: Editing shapefiles with Python</title>
      <link>https://community.esri.com/t5/python-questions/editing-shapefiles-with-python/m-p/257017#M19770</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It would be useful to give the forum some code to start with. You may need arcpy.AddField_management and arcpy.CalculateField_management to get started with the loop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Naresh Pai&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 01 Apr 2012 18:53:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/editing-shapefiles-with-python/m-p/257017#M19770</guid>
      <dc:creator>NareshPai</dc:creator>
      <dc:date>2012-04-01T18:53:19Z</dc:date>
    </item>
    <item>
      <title>Re: Editing shapefiles with Python</title>
      <link>https://community.esri.com/t5/python-questions/editing-shapefiles-with-python/m-p/257018#M19771</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Sorry about that.&amp;nbsp; Here is what I have so far.&amp;nbsp; For simplicity on the forum, I have just one shapefile in the code for now.&amp;nbsp; If I can get help with the code to do what I want on one, I can build the for loop to do the rest with the remaining shapefiles in a list.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt; 
# Import modules
import arcpy
import math

# Local variables:
point_shp = "R:\\Tornado Research\\test\\SfcOA.shp"


newfield = R_WsdpSfc
input = "getclass(double(!WSPD_SFC!))" #Not sure how to get the input file in this line of code
expression = "round([input]/5.0, 0) * 5.0" #Not sure if this is the correct way of doing this line

# Process: Add Field
arcpy.AddField_management(point_shp, newfield, "DOUBLE", "", "", "25", "", "NON_NULLABLE", "NON_REQUIRED", "") # Works fine

# Execute CalculateField 
arcpy.CalculateField_management(point_shp, newfield, expression, "PYTHON") #Obviously this line is broken

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The "Add Field" command works just fine, I just cant figure out the "Calculate Field" segment.&amp;nbsp; Thanks Again!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:40:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/editing-shapefiles-with-python/m-p/257018#M19771</guid>
      <dc:creator>CharlesGant</dc:creator>
      <dc:date>2021-12-11T12:40:48Z</dc:date>
    </item>
    <item>
      <title>Re: Editing shapefiles with Python</title>
      <link>https://community.esri.com/t5/python-questions/editing-shapefiles-with-python/m-p/257019#M19772</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try changing your expression variable to:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;expression = "round(!WSPD_SFC!/5.0, 0) * 5.0"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Since the expression is quoted as a string, it will not read 'input' as a variable.&amp;nbsp; It will read this as a string literal.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Apr 2012 11:01:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/editing-shapefiles-with-python/m-p/257019#M19772</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2012-04-02T11:01:13Z</dc:date>
    </item>
    <item>
      <title>Re: Editing shapefiles with Python</title>
      <link>https://community.esri.com/t5/python-questions/editing-shapefiles-with-python/m-p/257020#M19773</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Try changing your expression variable to:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;expression = "round(!WSPD_SFC!/5.0, 0) * 5.0"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Since the expression is quoted as a string, it will not read 'input' as a variable.&amp;nbsp; It will read this as a string literal.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wow, I dont know why I did not realize that!&amp;nbsp; I completely overlooked it.&amp;nbsp; That fixed it!&amp;nbsp; I guess sometimes when you stare at this stuff for so long, eventually you just need a new set of eyes to look it over.&amp;nbsp; Thanks Jake!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Apr 2012 11:20:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/editing-shapefiles-with-python/m-p/257020#M19773</guid>
      <dc:creator>CharlesGant</dc:creator>
      <dc:date>2012-04-02T11:20:22Z</dc:date>
    </item>
  </channel>
</rss>

