<?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: Grouping feature class rows based on a common attribute not working in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/grouping-feature-class-rows-based-on-a-common/m-p/1170347#M64474</link>
    <description>&lt;P&gt;Yes, perfect!&amp;nbsp; Thanks!&lt;/P&gt;</description>
    <pubDate>Tue, 03 May 2022 20:15:43 GMT</pubDate>
    <dc:creator>EricEagle</dc:creator>
    <dc:date>2022-05-03T20:15:43Z</dc:date>
    <item>
      <title>Grouping feature class rows based on a common attribute not working</title>
      <link>https://community.esri.com/t5/python-questions/grouping-feature-class-rows-based-on-a-common/m-p/1170155#M64462</link>
      <description>&lt;P&gt;I've got a point feature class that is a result of &lt;STRONG&gt;BearingDistanceToLine&lt;/STRONG&gt; --&amp;gt; &lt;STRONG&gt;GeneratePointsAlongLines&lt;/STRONG&gt;.&amp;nbsp; It has generated around 150 points associated with about 400 lines.&lt;/P&gt;&lt;P&gt;I'm attempting to go in and add curvature offsets to each point in this feature class based on its distance from its associated origin point.&amp;nbsp; The easiest way for me to do this is to bundle the features by the ORIG_FID field and then sort by OID@ (first is the origin, last is the furthest distance).&amp;nbsp; Similar to using a track ID in trajectory data.&lt;/P&gt;&lt;P&gt;I'm trying to put it all in a dictionary that should look like this, and then use built in math package to do the calculations across the dictionary, and construct a new feature class (maybe faster than doing UpdateCursor).&amp;nbsp; Anyway it should look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;{1: [row, row, row, row],
 2: [row, row, row, row],
 ....
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is how I'm attempting to implement, probably poorly:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.SearchCursor("samplepoints", ["OID@", "ORIG_FID", "curvature"]) as cursor:
    uniques = sorted({row[1] for row in cursor})
    c = {i: [row for row in cursor if row[1] == i] for i in uniques}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This ends up creating a dictionary that does pull the unique ORIG_FID in as keys, and sets the value as a list, but adds no rows.&amp;nbsp; Even though each ORIG_FID should be common to around 150 rows.&lt;/P&gt;&lt;P&gt;Why is it not adding the rows even though row[1] should match i?&lt;/P&gt;</description>
      <pubDate>Tue, 03 May 2022 16:23:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/grouping-feature-class-rows-based-on-a-common/m-p/1170155#M64462</guid>
      <dc:creator>EricEagle</dc:creator>
      <dc:date>2022-05-03T16:23:50Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping feature class rows based on a common attribute not working</title>
      <link>https://community.esri.com/t5/python-questions/grouping-feature-class-rows-based-on-a-common/m-p/1170306#M64470</link>
      <description>&lt;P&gt;I'm not fully following what you are trying to do here, but it looks like you should be using an&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/2.8/arcpy/data-access/updatecursor-class.htm" target="_self"&gt;UpdateCursor&lt;/A&gt;&amp;nbsp;if you're trying to change values or an&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/2.8/arcpy/data-access/insertcursor-class.htm" target="_self"&gt;InsertCursor&lt;/A&gt;&amp;nbsp;if you're trying to add new rows.&lt;/P&gt;&lt;P&gt;Perhaps your c value (or maybe the dictionary value?) needs to be assigned back to the data source using one of the cursors I linked.&lt;/P&gt;</description>
      <pubDate>Tue, 03 May 2022 19:06:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/grouping-feature-class-rows-based-on-a-common/m-p/1170306#M64470</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-05-03T19:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping feature class rows based on a common attribute not working</title>
      <link>https://community.esri.com/t5/python-questions/grouping-feature-class-rows-based-on-a-common/m-p/1170326#M64473</link>
      <description>&lt;P&gt;Does this do it?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
from collections import defaultdict

c = defaultdict(list)
with arcpy.da.SearchCursor("samplepoints", ["OID@", "ORIG_FID", "curvature"]) as cursor:
    for row in cursor:
        c[row[1]].append(row)&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 03 May 2022 19:47:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/grouping-feature-class-rows-based-on-a-common/m-p/1170326#M64473</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2022-05-03T19:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping feature class rows based on a common attribute not working</title>
      <link>https://community.esri.com/t5/python-questions/grouping-feature-class-rows-based-on-a-common/m-p/1170347#M64474</link>
      <description>&lt;P&gt;Yes, perfect!&amp;nbsp; Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 03 May 2022 20:15:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/grouping-feature-class-rows-based-on-a-common/m-p/1170347#M64474</guid>
      <dc:creator>EricEagle</dc:creator>
      <dc:date>2022-05-03T20:15:43Z</dc:date>
    </item>
  </channel>
</rss>

