<?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: Cursor Performance against Layer Selections in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/cursor-performance-against-layer-selections/m-p/1523010#M71272</link>
    <description>&lt;P&gt;I haven't run into this issue myself, but you could try something like:&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;selected_stuff = arcpy.GetParameter('selection')  # feature layer input with a selection applied

actualFC = selected_stuff.dataSource
selSet = selected_stuff.getSelectionSet() # get set of OIDs of selected feature

sql = f"OBJECTID IN ({', '.join([str(i) for i in selSet])})"

metrics = {id: metric for id, metric in results}  # parse through some table of results to get the stuff I want to update

with arcpy.da.UpdateCursor(
        actualFC,
        field_names=['id', 'metric'],
        where_clause = sql
) as i_cursor:
    for row in i_cursor:
        metric = metrics.get(row[0])

        if metric and metric != row[1]:

            row[1] = metric
            i_cursor.updateRow(row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;Basically, run the cursor on the actual table based on what you have selected, rather than on the layer.&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Fri, 16 Aug 2024 17:14:55 GMT</pubDate>
    <dc:creator>AlfredBaldenweck</dc:creator>
    <dc:date>2024-08-16T17:14:55Z</dc:date>
    <item>
      <title>Cursor Performance against Layer Selections</title>
      <link>https://community.esri.com/t5/python-questions/cursor-performance-against-layer-selections/m-p/1523003#M71271</link>
      <description>&lt;P&gt;I've been passing the results of selections against layers directly to the arcpy.da.UpdateCursor, and noticed that the performance is terrible. I love the convenience of not deriving some whacky SQL to tell the cursor exactly what I want to update...but at this point, the juice ain't worth the squeeze.&lt;/P&gt;&lt;P&gt;Any tips on making this work? The process is usually something like&lt;/P&gt;&lt;LI-CODE lang="python"&gt;selected_stuff = arcpy.GetParameter('selection')  # feature layer input with a selection applied

metrics = {id: metric for id, metric in results}  # parse through some table of results to get the stuff I wan to update

with arcpy.da.UpdateCursor(
        selected_stuff,
        field_names=['id', 'metric'],
) as i_cursor:
    for row in i_cursor:
        metric = metrics.get(row[0])

        if metric and metric != row[1]:

            row[1] = metric
            i_cursor.updateRow(row)&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 16 Aug 2024 16:49:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cursor-performance-against-layer-selections/m-p/1523003#M71271</guid>
      <dc:creator>tcrammond</dc:creator>
      <dc:date>2024-08-16T16:49:45Z</dc:date>
    </item>
    <item>
      <title>Re: Cursor Performance against Layer Selections</title>
      <link>https://community.esri.com/t5/python-questions/cursor-performance-against-layer-selections/m-p/1523010#M71272</link>
      <description>&lt;P&gt;I haven't run into this issue myself, but you could try something like:&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;selected_stuff = arcpy.GetParameter('selection')  # feature layer input with a selection applied

actualFC = selected_stuff.dataSource
selSet = selected_stuff.getSelectionSet() # get set of OIDs of selected feature

sql = f"OBJECTID IN ({', '.join([str(i) for i in selSet])})"

metrics = {id: metric for id, metric in results}  # parse through some table of results to get the stuff I want to update

with arcpy.da.UpdateCursor(
        actualFC,
        field_names=['id', 'metric'],
        where_clause = sql
) as i_cursor:
    for row in i_cursor:
        metric = metrics.get(row[0])

        if metric and metric != row[1]:

            row[1] = metric
            i_cursor.updateRow(row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;Basically, run the cursor on the actual table based on what you have selected, rather than on the layer.&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 16 Aug 2024 17:14:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cursor-performance-against-layer-selections/m-p/1523010#M71272</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2024-08-16T17:14:55Z</dc:date>
    </item>
  </channel>
</rss>

