<?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 Parse the OID field using an Update Cursor in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/parse-the-oid-field-using-an-update-cursor/m-p/530800#M17684</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a feature class within a geodatabase that has a field called 'cellnum' and also, by default, has an OID field. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to create an Update Cursor that will read the OID number, take the last digit, subtract it by 1, and add that value to the field 'cellnum'.&amp;nbsp; So, if the OID is 614, the cellnum value should be 3-- last digit of 614 is 4, minus 1 is 3).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have something like this already:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;sort = "C:/User/Username/Documents/project/ABE.gdb/cellanalysis_Sort1"
rows3 = arcpy.UpdateCursor(sort)
for row3 in rows3:
&amp;nbsp;&amp;nbsp;&amp;nbsp; fUpdate = arcpy.Describe(sort)
&amp;nbsp;&amp;nbsp;&amp;nbsp; num = row3.getValue("ID")
&amp;nbsp;&amp;nbsp;&amp;nbsp; OID = fUpdate.OIDFieldName
&amp;nbsp;&amp;nbsp;&amp;nbsp; value = row3.getValue(OID)
&amp;nbsp;&amp;nbsp;&amp;nbsp; digit = value[-1] - 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "for ID:" + str(num) + " the cellnum is " + digit
del row3,rows3&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, python doesn't like my 'digit' statement.&amp;nbsp; Can anyone shed some light on this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 24 Jan 2011 20:56:59 GMT</pubDate>
    <dc:creator>ChristinaHerrick1</dc:creator>
    <dc:date>2011-01-24T20:56:59Z</dc:date>
    <item>
      <title>Parse the OID field using an Update Cursor</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/parse-the-oid-field-using-an-update-cursor/m-p/530800#M17684</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a feature class within a geodatabase that has a field called 'cellnum' and also, by default, has an OID field. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to create an Update Cursor that will read the OID number, take the last digit, subtract it by 1, and add that value to the field 'cellnum'.&amp;nbsp; So, if the OID is 614, the cellnum value should be 3-- last digit of 614 is 4, minus 1 is 3).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have something like this already:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;sort = "C:/User/Username/Documents/project/ABE.gdb/cellanalysis_Sort1"
rows3 = arcpy.UpdateCursor(sort)
for row3 in rows3:
&amp;nbsp;&amp;nbsp;&amp;nbsp; fUpdate = arcpy.Describe(sort)
&amp;nbsp;&amp;nbsp;&amp;nbsp; num = row3.getValue("ID")
&amp;nbsp;&amp;nbsp;&amp;nbsp; OID = fUpdate.OIDFieldName
&amp;nbsp;&amp;nbsp;&amp;nbsp; value = row3.getValue(OID)
&amp;nbsp;&amp;nbsp;&amp;nbsp; digit = value[-1] - 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "for ID:" + str(num) + " the cellnum is " + digit
del row3,rows3&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, python doesn't like my 'digit' statement.&amp;nbsp; Can anyone shed some light on this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Jan 2011 20:56:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/parse-the-oid-field-using-an-update-cursor/m-p/530800#M17684</guid>
      <dc:creator>ChristinaHerrick1</dc:creator>
      <dc:date>2011-01-24T20:56:59Z</dc:date>
    </item>
    <item>
      <title>Re: Parse the OID field using an Update Cursor</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/parse-the-oid-field-using-an-update-cursor/m-p/530801#M17685</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Christina,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I had to convert the OBJECTID value to a string, get the last number, then convert back to integer to subtract (- 1).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;There may be a "cleaner" way to do it, but this works:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

arcpy.env.workspace = os.getcwd()

fc = "temp.gdb/Business"

# Create update cursor for feature class.
rows = arcpy.UpdateCursor(fc)
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Get the value from the field
&amp;nbsp;&amp;nbsp;&amp;nbsp; oid = row.getValue("OBJECTID")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Convert to string
&amp;nbsp;&amp;nbsp;&amp;nbsp; x = str(oid)[-1]
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Convert to integer
&amp;nbsp;&amp;nbsp;&amp;nbsp; y = int(x) - 1&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; print y

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Set results to field 'num'&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; row.num = y&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Execute the new value to the table
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.UpdateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
del rows&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:06:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/parse-the-oid-field-using-an-update-cursor/m-p/530801#M17685</guid>
      <dc:creator>RDHarles</dc:creator>
      <dc:date>2021-12-11T23:06:37Z</dc:date>
    </item>
    <item>
      <title>Re: Parse the OID field using an Update Cursor</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/parse-the-oid-field-using-an-update-cursor/m-p/530802#M17686</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Cleaner way:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def last_digit_minus_1(number):
&amp;nbsp;&amp;nbsp;&amp;nbsp; return (number - 1) % 10
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:06:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/parse-the-oid-field-using-an-update-cursor/m-p/530802#M17686</guid>
      <dc:creator>NiklasNorrthon</dc:creator>
      <dc:date>2021-12-11T23:06:40Z</dc:date>
    </item>
  </channel>
</rss>

