<?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: How to calculate field as cursor name? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-calculate-field-as-cursor-name/m-p/182127#M14009</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Have you tried the 'Spatial Join' tool:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#/Spatial_Join/00080000000q000000/"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#/Spatial_Join/00080000000q000000/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Seems like it should be able to do what you are trying to do.&amp;nbsp; I don't think you need to necessarily use a cursor here. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, on your code the SelectLayerByLocation_management tool's third argument should be a feature layer. You are putting a Geometry object in for it.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 14 Sep 2012 20:59:11 GMT</pubDate>
    <dc:creator>GeorgeNewbury</dc:creator>
    <dc:date>2012-09-14T20:59:11Z</dc:date>
    <item>
      <title>How to calculate field as cursor name?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-calculate-field-as-cursor-name/m-p/182126#M14008</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;First time dealing with cursor. I have lines intersecting polygons, I want to get a table with all attributes of the lines, add a field and calculate the field as the name of the polygon. I was able to get a table for each polygon but I can't get to calculate the field and add the polygon name. How do I do? here is my code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
arcpy.env.overwriteOutput = True

arcpy.env.workspace = 'C:\\Users\\a391665\\Documents\\ArcGIS\\Default.gdb'
ws = 'C:\\Users\\a391665\\Documents\\ArcGIS\\Default.gdb'
Comuni = 'C:\\Users\\a391665\\Documents\\ArcGIS\\Sardegna3.gdb\\Comuni'
Linee = 'C:\\Users\\a391665\\Documents\\ArcGIS\\Sardegna3.gdb\\Linee' 

rows = arcpy.SearchCursor(Comuni)

for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print row.NOME
&amp;nbsp;&amp;nbsp;&amp;nbsp; feat = row.Shape
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management("Linee", "INTERSECT", feat, selection_type="NEW_SELECTION");
&amp;nbsp;&amp;nbsp;&amp;nbsp; out_feature_class = arcpy.ValidateTableName("Linee_Clip_" + row.NOME);
&amp;nbsp;&amp;nbsp;&amp;nbsp; table = arcpy.TableToTable_conversion("Linee", ws, out_feature_class);
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(out_feature_class, 'Clip', 'TEXT', '', '', '60');
&amp;nbsp;&amp;nbsp;&amp;nbsp; expression = arcpy.ValidateTableName(row.NOME);
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(table, "Clip", expression);&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;here is the error I get:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Empty value for ObjectID = 1 The calculated value is invalid for the row with ObjectID = 1. For example, the calculated value may be too large for the field or you may be trying to add a string to a number field. This row will not be updated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:09:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-calculate-field-as-cursor-name/m-p/182126#M14008</guid>
      <dc:creator>LucaMoiana</dc:creator>
      <dc:date>2021-12-12T16:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate field as cursor name?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-calculate-field-as-cursor-name/m-p/182127#M14009</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Have you tried the 'Spatial Join' tool:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#/Spatial_Join/00080000000q000000/"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#/Spatial_Join/00080000000q000000/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Seems like it should be able to do what you are trying to do.&amp;nbsp; I don't think you need to necessarily use a cursor here. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, on your code the SelectLayerByLocation_management tool's third argument should be a feature layer. You are putting a Geometry object in for it.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Sep 2012 20:59:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-calculate-field-as-cursor-name/m-p/182127#M14009</guid>
      <dc:creator>GeorgeNewbury</dc:creator>
      <dc:date>2012-09-14T20:59:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate field as cursor name?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-calculate-field-as-cursor-name/m-p/182128#M14010</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi George, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your help. I ended up, thank to the help of the forum, I ended up doing a second cursor, I'll attach the code below. Spatial Join is a solution I didn't explore, but I'll try.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Cause otherwise I now have to find a way to append the tables...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
arcpy.env.overwriteOutput = True

arcpy.env.workspace = 'C:\\Users\\a391665\\Documents\\ArcGIS\\Default.gdb'
ws = 'C:\\Users\\a391665\\Documents\\ArcGIS\\Default.gdb'
Comuni = 'C:\\Users\\a391665\\Documents\\ArcGIS\\Sardegna3.gdb\\Comuni'
Linee = 'C:\\Users\\a391665\\Documents\\ArcGIS\\Sardegna3.gdb\\Linee' 

rows = arcpy.SearchCursor(Comuni)

for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print row.NOME
&amp;nbsp;&amp;nbsp;&amp;nbsp; feat = row.Shape
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management("Linee", "INTERSECT", feat, selection_type="NEW_SELECTION");
&amp;nbsp;&amp;nbsp;&amp;nbsp; out_feature_class = arcpy.ValidateTableName("Linee_Clip_" + row.NOME);
&amp;nbsp;&amp;nbsp;&amp;nbsp; table = arcpy.TableToTable_conversion("Linee", ws, out_feature_class);
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(out_feature_class, 'Comune', 'TEXT', '', '', '60');
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(out_feature_class, 'ISTAT', 'TEXT', '', '', '6');
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows2 = arcpy.UpdateCursor(table)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row2 in rows2:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row2.Comune = str(row.NOME)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row2.ISTAT = str(row.CODISTAT)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows2.updateRow(row2)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:17:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-calculate-field-as-cursor-name/m-p/182128#M14010</guid>
      <dc:creator>LucaMoiana</dc:creator>
      <dc:date>2021-12-11T09:17:56Z</dc:date>
    </item>
  </channel>
</rss>

