<?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 do you insert both attributes and geometry with an InsertCursor? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-do-you-insert-both-attributes-and-geometry/m-p/55702#M4401</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;EDIT: Ok I think I understand a bit better after rereading, I think what you are trying to do should work, however I have had issues doing it like that! My implementation wasnt how I wanted it to be, but went like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(Code may only work with standard InsertCursor, not the .da version!)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Insert the current superstring into the output feature class
cursorFieldList = dissolveFields
cursorFieldList.append("SHAPE@")
insertCursor2 = arcpy.da.InsertCursor('SuperStrings_temp_out', cursorFieldList)
#Create empty template row object
insertRow = insertCursor2.newRow()
multipartPolyline = arcpy.Polyline(superstringPartsArray)


#Set geometry
insertRow.shape = multipartPolyline


#Set other fields
insertRow.setValue(field1, row.getValue(field1))
insertRow.setValue(field2, row.getValue(field2))
insertCursor2.insertRow(insertRow)


del insertCursor2, insertRow&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 22:07:18 GMT</pubDate>
    <dc:creator>LukeWebb</dc:creator>
    <dc:date>2021-12-10T22:07:18Z</dc:date>
    <item>
      <title>How do you insert both attributes and geometry with an InsertCursor?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-insert-both-attributes-and-geometry/m-p/55701#M4400</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to use an insert cursor to populate several fields with attributes and also the SHAPE field with a multi-part polyline, but I keep getting a "can only concatenate tuple (not "list") to tuple" error. I don't understand, because it works to insert just the SHAPE surrounded by square brackets, and my row from an outer SearchCursor works as a list everywhere else! (Converting to a tuple doesn't work either!).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Insert the current superstring into the output feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; insertCursor2 = arcpy.da.InsertCursor('SuperStrings_temp_out', dissolveFields + ["SHAPE@"])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; multipartPolyline = arcpy.Polyline(superstringPartsArray)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; insertCursor2.insertRow(row + [[multipartPolyline]])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del insertCursor2&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;'dissolveFields' is the list of fields whose attributes I want to update with 'row', which is the current row of a table of unique combinations (from the summary statistics tool), which has the same fields as in the dissolveFields list.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:07:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-insert-both-attributes-and-geometry/m-p/55701#M4400</guid>
      <dc:creator>DanEvans</dc:creator>
      <dc:date>2021-12-10T22:07:15Z</dc:date>
    </item>
    <item>
      <title>Re: How do you insert both attributes and geometry with an InsertCursor?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-insert-both-attributes-and-geometry/m-p/55702#M4401</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;EDIT: Ok I think I understand a bit better after rereading, I think what you are trying to do should work, however I have had issues doing it like that! My implementation wasnt how I wanted it to be, but went like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(Code may only work with standard InsertCursor, not the .da version!)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Insert the current superstring into the output feature class
cursorFieldList = dissolveFields
cursorFieldList.append("SHAPE@")
insertCursor2 = arcpy.da.InsertCursor('SuperStrings_temp_out', cursorFieldList)
#Create empty template row object
insertRow = insertCursor2.newRow()
multipartPolyline = arcpy.Polyline(superstringPartsArray)


#Set geometry
insertRow.shape = multipartPolyline


#Set other fields
insertRow.setValue(field1, row.getValue(field1))
insertRow.setValue(field2, row.getValue(field2))
insertCursor2.insertRow(insertRow)


del insertCursor2, insertRow&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:07:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-insert-both-attributes-and-geometry/m-p/55702#M4401</guid>
      <dc:creator>LukeWebb</dc:creator>
      <dc:date>2021-12-10T22:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do you insert both attributes and geometry with an InsertCursor?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-insert-both-attributes-and-geometry/m-p/55703#M4402</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are using a plus sign in your fields list which means it's trying to add them together. Change to&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14570971552887639" data-renderedposition="34_8_872_16" jivemacro_uid="_14570971552887639"&gt;&lt;P&gt;insertCursor2 = arcpy.da.InsertCursor('SuperStrings_temp_out', [dissolveFields, "SHAPE@"]) &lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Mar 2016 13:12:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-insert-both-attributes-and-geometry/m-p/55703#M4402</guid>
      <dc:creator>WesMiller</dc:creator>
      <dc:date>2016-03-04T13:12:40Z</dc:date>
    </item>
    <item>
      <title>Re: How do you insert both attributes and geometry with an InsertCursor?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-insert-both-attributes-and-geometry/m-p/55704#M4403</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, managed to solve it though.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Turns out converting to a tuple did work, I just had to keep the square brackets around multipartPolyline - although actually what I ended up doing was instead converting 'row' to a list as I had a few other fields to add and it made sense to only do one conversion to list rather than multiple to tuple!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now my code looks like this:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Insert the current superstring into the output feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; insertCursor2 = arcpy.da.InsertCursor('SuperStrings_temp_out', dissolveFields + ["FREQUENCY", "SUM_SHAPE_Length", "SHAPE@"])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; multipartPolyline = arcpy.Polyline(superstringPartsArray)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; insertCursor2.insertRow(list(row) + [count] + [multipartPolyline.length] + [multipartPolyline])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del insertCursor2&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I just don't understand how 'row', which I treat like a list with no problems earlier on in the code, has suddenly become a tuple!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:07:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-insert-both-attributes-and-geometry/m-p/55704#M4403</guid>
      <dc:creator>DanEvans</dc:creator>
      <dc:date>2021-12-10T22:07:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do you insert both attributes and geometry with an InsertCursor?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-insert-both-attributes-and-geometry/m-p/55705#M4404</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Would that not add 'dissolveFields' as a list element within the list?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Mar 2016 13:16:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-insert-both-attributes-and-geometry/m-p/55705#M4404</guid>
      <dc:creator>DanEvans</dc:creator>
      <dc:date>2016-03-04T13:16:05Z</dc:date>
    </item>
    <item>
      <title>Re: How do you insert both attributes and geometry with an InsertCursor?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-insert-both-attributes-and-geometry/m-p/55706#M4405</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I hope this link works &lt;A href="http://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-data-access/insertcursor-class.htm" title="http://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-data-access/insertcursor-class.htm"&gt;InsertCursor—Help | ArcGIS for Desktop&lt;/A&gt; please see the examples at the bottom of the page&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EDIT:&lt;/P&gt;&lt;P&gt;You would create a field list like below:&lt;/P&gt;&lt;P&gt;field_list = [field1,field2,field3]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you use the plus you are adding or concatenating:&lt;/P&gt;&lt;P&gt;1+1 =2&lt;/P&gt;&lt;P&gt;"value" + "othervalue" = "valueothervalue"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Mar 2016 15:02:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-insert-both-attributes-and-geometry/m-p/55706#M4405</guid>
      <dc:creator>WesMiller</dc:creator>
      <dc:date>2016-03-04T15:02:33Z</dc:date>
    </item>
  </channel>
</rss>

