<?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 Update Cursor and Joined Tables in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/update-cursor-and-joined-tables/m-p/636793#M49576</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Is it possible to access joined tables using arcpy.UpdateCursor? I have no problems access a joined table with arcpy.SearchCursor, but when I attempt it with Update, it errors out.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It errors on the arcpy.UpdateCursor(soil) I think because the update cursor doesn't like feature layers, but I change it to the feature class SOIL, the 2 str(row.getValue... syntaxes won't read the field names....I'm stumped.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
import arcpy
from arcpy import env

env.workspace = r"Z:\Test.gdb"

arcpy.SpatialJoin_analysis("SOIL", "TERRAIN", "SPATIAL")

soil = "\"soil\""

arcpy.MakeFeatureLayer_management("SO_SOIL_P", soil)

arcpy.AddJoin_management(soil, "SITE_ID", "SPATIAL", "SITE_ID")

rows = arcpy.UpdateCursor(soil)

for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print str(row.getValue("SOIL.SITE_ID"))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print str(row.getValue("SPATIAL.TSSD"))
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 28 Feb 2012 21:01:18 GMT</pubDate>
    <dc:creator>MikeMacRae</dc:creator>
    <dc:date>2012-02-28T21:01:18Z</dc:date>
    <item>
      <title>Update Cursor and Joined Tables</title>
      <link>https://community.esri.com/t5/python-questions/update-cursor-and-joined-tables/m-p/636793#M49576</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Is it possible to access joined tables using arcpy.UpdateCursor? I have no problems access a joined table with arcpy.SearchCursor, but when I attempt it with Update, it errors out.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It errors on the arcpy.UpdateCursor(soil) I think because the update cursor doesn't like feature layers, but I change it to the feature class SOIL, the 2 str(row.getValue... syntaxes won't read the field names....I'm stumped.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
import arcpy
from arcpy import env

env.workspace = r"Z:\Test.gdb"

arcpy.SpatialJoin_analysis("SOIL", "TERRAIN", "SPATIAL")

soil = "\"soil\""

arcpy.MakeFeatureLayer_management("SO_SOIL_P", soil)

arcpy.AddJoin_management(soil, "SITE_ID", "SPATIAL", "SITE_ID")

rows = arcpy.UpdateCursor(soil)

for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print str(row.getValue("SOIL.SITE_ID"))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print str(row.getValue("SPATIAL.TSSD"))
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Feb 2012 21:01:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursor-and-joined-tables/m-p/636793#M49576</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2012-02-28T21:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: Update Cursor and Joined Tables</title>
      <link>https://community.esri.com/t5/python-questions/update-cursor-and-joined-tables/m-p/636794#M49577</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I found an older thread. It looks like this is still a known issue:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.arcgis.com/threads/9507-Update-cursor-on-joined-tables"&gt;http://forums.arcgis.com/threads/9507-Update-cursor-on-joined-tables&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Feb 2012 21:54:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursor-and-joined-tables/m-p/636794#M49577</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2012-02-28T21:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: Update Cursor and Joined Tables</title>
      <link>https://community.esri.com/t5/python-questions/update-cursor-and-joined-tables/m-p/636795#M49578</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Unfortunately, join and update cursor won't work. I wrote the following function to get around&amp;nbsp;AddJoin_management and CalculateField_management. CalculateField_management kept failing on 100k record datasets.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def JoinAndUpdateField(fcTblPrimary, strJoinFldPrimary, fcTblForeign, strJoinFldForeign, strUpdateFldPrimary, strUpdateFldForeign, methodToProcess=None):&lt;BR /&gt; """&lt;BR /&gt; Joins two tables or feature classes or combination and updates one field from another with optional passed method to update the value further.&lt;/P&gt;&lt;P&gt;The same result can be gotten with arcpy AddJoin_management and CalculateField_management, but CalculateField_management kept failing on 100k record datasets.&lt;/P&gt;&lt;P&gt;Parameters&lt;BR /&gt; ----------&lt;BR /&gt; fcTblPrimary : str&lt;BR /&gt; Full path to a fc or table&lt;BR /&gt; e.g. c:/proj/data.gdb/datasetA or c:/proj/USER@VECTOR.sde/datasetB or Database Connections/USER@VECTOR.sde/datasetC&lt;BR /&gt; strJoinFldPrimary : str&lt;BR /&gt; Field of primary table to join on&lt;BR /&gt; fcTblForeign : str&lt;BR /&gt; Full path to a fc or table to join to&lt;BR /&gt; strJoinFldForeign : str&lt;BR /&gt; Field of secondary table to join on&lt;BR /&gt; strUpdateFldPrimary : str&lt;BR /&gt; Field to update&lt;BR /&gt; strUpdateFldForeign : str&lt;BR /&gt; Field to get value from for the update&lt;BR /&gt; methodToProcess : method&lt;BR /&gt; Optional Method to process the strUpdateFldForeign field before updating&lt;BR /&gt; """&lt;BR /&gt; dictValues = dict ([(key, val) for key, val in arcpy.da.SearchCursor (fcTblForeign, [strJoinFldForeign, strUpdateFldForeign])])&lt;BR /&gt; boolUseMethod = False &lt;BR /&gt; if methodToProcess:&lt;BR /&gt; boolUseMethod = True &lt;BR /&gt; with arcpy.da.UpdateCursor(fcTblPrimary, [strJoinFldPrimary,strUpdateFldPrimary]) as cursor:&lt;BR /&gt; for row in cursor:&lt;BR /&gt; try:&lt;BR /&gt; if boolUseMethod:&lt;BR /&gt; row[1] = methodToProcess(dictValues[row[0]])&lt;BR /&gt; else:&lt;BR /&gt; row[1] = dictValues[row[0]]&lt;BR /&gt; except KeyError:&lt;BR /&gt; pass&lt;BR /&gt; cursor.updateRow(row)&lt;BR /&gt; del cursor&lt;BR /&gt; del dictValues&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Sep 2017 21:41:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursor-and-joined-tables/m-p/636795#M49578</guid>
      <dc:creator>DouglasHall</dc:creator>
      <dc:date>2017-09-19T21:41:21Z</dc:date>
    </item>
  </channel>
</rss>

