<?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: Insert.cursor Error While Copying Geometries in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/insert-cursor-error-while-copying-geometries/m-p/1157624#M64157</link>
    <description>&lt;P&gt;an updatecursor would be a better bet if you are altering existing data&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/updatecursor-class.htm" target="_blank"&gt;UpdateCursor—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;it supports "with" syntax&lt;/P&gt;</description>
    <pubDate>Thu, 24 Mar 2022 23:53:07 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2022-03-24T23:53:07Z</dc:date>
    <item>
      <title>Insert.cursor Error While Copying Geometries</title>
      <link>https://community.esri.com/t5/python-questions/insert-cursor-error-while-copying-geometries/m-p/1157623#M64156</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm trying to insert/create geometries using "feature A" geometries&amp;nbsp; into feature B, which has null geometries .&amp;nbsp; It seems simple enough but I'm not well acquainted with programming.&amp;nbsp; This is what I have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

#Setup environment and variables
arcpy.env.workspace = r'C:\\Users\\xxxx\\OneDrive - xxxxxxx, BUREAU OF TECH. SERVICES\\Documents\\ArcGIS\\Projects\\Migration\\ Migration.gdb'
A = 'Easement_for_Treat'
idfieldA = 'IDFieldA'
B = "Work_Area_Migration_Merge"
idfieldB = 'IDFieldB'

#Build a dictionary with IDs as keys and geometries as value
geometries = {key:value for (key,value) in arcpy.da.SearchCursor(A, [idfieldA, 'SHAPE@'])}

#Empty list to store ids in B not found in A
notfound = []

#Insert B with geometries from A where ID:s match
with arcpy.da.InsertCursor(B, [idfieldB, 'SHAPE@']) as cursor:
    for row in cursor:
        try:
            row[1] = geometries[row[0]]
            insert.updateRow(row)
        except:
            notfound.append(row[0])
            &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get thrown this exception:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;---------------------------------------------------------------------------&lt;/SPAN&gt;
&lt;SPAN class=""&gt;TypeError&lt;/SPAN&gt;                                 Traceback (most recent call last)
In  &lt;SPAN class=""&gt;[2]&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;18&lt;/SPAN&gt;:    &lt;SPAN class=""&gt;for&lt;/SPAN&gt; row &lt;SPAN class=""&gt;in&lt;/SPAN&gt; cursor:

&lt;SPAN class=""&gt;TypeError&lt;/SPAN&gt;: 'da.InsertCursor' object is not iterable
&lt;SPAN class=""&gt;---------------------------------------------------------------------------&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Any guidance would be greatly appreciated!&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2022 23:41:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/insert-cursor-error-while-copying-geometries/m-p/1157623#M64156</guid>
      <dc:creator>Jefcoat_Nathan</dc:creator>
      <dc:date>2022-03-24T23:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: Insert.cursor Error While Copying Geometries</title>
      <link>https://community.esri.com/t5/python-questions/insert-cursor-error-while-copying-geometries/m-p/1157624#M64157</link>
      <description>&lt;P&gt;an updatecursor would be a better bet if you are altering existing data&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/updatecursor-class.htm" target="_blank"&gt;UpdateCursor—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;it supports "with" syntax&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2022 23:53:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/insert-cursor-error-while-copying-geometries/m-p/1157624#M64157</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-03-24T23:53:07Z</dc:date>
    </item>
    <item>
      <title>Re: Insert.cursor Error While Copying Geometries</title>
      <link>https://community.esri.com/t5/python-questions/insert-cursor-error-while-copying-geometries/m-p/1157632#M64159</link>
      <description>&lt;P&gt;You don't iterate an InsertCursor (for row in cursor) since you're just adding rows. try something like this&lt;/P&gt;&lt;LI-CODE lang="python"&gt;iCur = arcpy.da.InsertCursor(table, ["ID", "SHAPE@X", "SHAPE@Y"])
for k, v in geometries.items():
    row = (k, v[0], v[1])
    iCur.insertRow(row)&lt;/LI-CODE&gt;&lt;P&gt;I've never tried to insert a complete shape object which is why I split it out in the example. that may be unnecessary.&lt;/P&gt;&lt;P&gt;also, if you're trying to update an existing records with geometries, you'd want to use an UpdateCursor.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 00:03:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/insert-cursor-error-while-copying-geometries/m-p/1157632#M64159</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-03-25T00:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: Insert.cursor Error While Copying Geometries</title>
      <link>https://community.esri.com/t5/python-questions/insert-cursor-error-while-copying-geometries/m-p/1157698#M64162</link>
      <description>&lt;P&gt;As the others have said, you can't iterate an InsertCursor.&lt;/P&gt;&lt;P&gt;You want to update existing features in class B, so you need an UpdateCursor.&lt;/P&gt;&lt;P&gt;Starting from line 17 in your code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.UpdateCursor(B, [idfieldB, 'SHAPE@']) as cursor:
    for key, shape in cursor:  #iterate through the existing features in B
        try:
            new_shape = geometries[key]
            cursor.updateRow([key, new_shape])
        except KeyError:
            notfound.append(key)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2022 05:38:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/insert-cursor-error-while-copying-geometries/m-p/1157698#M64162</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-03-31T05:38:40Z</dc:date>
    </item>
    <item>
      <title>Re: Insert.cursor Error While Copying Geometries</title>
      <link>https://community.esri.com/t5/python-questions/insert-cursor-error-while-copying-geometries/m-p/1159070#M64206</link>
      <description>&lt;P&gt;Thanks for the help. I've updated the code but I'm getting thrown a NameError on insert.updateRow&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#Setup environment and variables
arcpy.env.workspace = r'C:\\Users\\xxx\\OneDrive - CITY OF xxxx, BUREAU OF TECH. SERVICES\\Documents\\ArcGIS\\Projects\\xxxxxxxx\\xxxxxxx Migration.gdb'
A = 'Easement_for_Treat'
idfieldA = 'IDFieldA'
B = "Work_Area_Migration_Merge"
idfieldB = 'IDFieldB'

#Build a dictionary with IDs as keys and geometries as value
geometries = {key:value for (key,value) in arcpy.da.SearchCursor(A, [idfieldA, 'SHAPE@Area'])}

#Empty list to store ids in B not found in A
notfound = []

#Insert B with geometries from A where ID:s match
with arcpy.da.UpdateCursor(B, [idfieldB, 'SHAPE@']) as cursor:
    for key, shape in cursor:  #iterate through the existing features in B
        try:
            new_shape = geometries[key]
            insert.updateRow([key, new_shape])
        except KeyError:
            notfound.append(key)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;--------------------------------------------------------------------------&lt;/SPAN&gt;
&lt;SPAN class=""&gt;NameError&lt;/SPAN&gt;                                 Traceback (most recent call last)
In  &lt;SPAN class=""&gt;[5]&lt;/SPAN&gt;:
Line &lt;SPAN class=""&gt;19&lt;/SPAN&gt;:    insert.UpdateRow([key, new_shape])

&lt;SPAN class=""&gt;NameError&lt;/SPAN&gt;: name 'insert' is not defined
&lt;SPAN class=""&gt;---------------------------------------------------------------------------&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Do I have the syntax wrong?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2022 19:43:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/insert-cursor-error-while-copying-geometries/m-p/1159070#M64206</guid>
      <dc:creator>Jefcoat_Nathan</dc:creator>
      <dc:date>2022-03-29T19:43:04Z</dc:date>
    </item>
    <item>
      <title>Re: Insert.cursor Error While Copying Geometries</title>
      <link>https://community.esri.com/t5/python-questions/insert-cursor-error-while-copying-geometries/m-p/1159072#M64207</link>
      <description>&lt;P&gt;I changed it to cursor.updateRow and it worked. Thank You!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2022 19:52:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/insert-cursor-error-while-copying-geometries/m-p/1159072#M64207</guid>
      <dc:creator>Jefcoat_Nathan</dc:creator>
      <dc:date>2022-03-29T19:52:34Z</dc:date>
    </item>
    <item>
      <title>Re: Insert.cursor Error While Copying Geometries</title>
      <link>https://community.esri.com/t5/python-questions/insert-cursor-error-while-copying-geometries/m-p/1159761#M64235</link>
      <description>&lt;P&gt;Oops, I didn't change all of the variable names... Fixed it in my answer.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2022 05:40:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/insert-cursor-error-while-copying-geometries/m-p/1159761#M64235</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-03-31T05:40:59Z</dc:date>
    </item>
  </channel>
</rss>

