<?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: Get Extent object for features returned by SearchCursor in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/get-extent-object-for-features-returned-by/m-p/724408#M56092</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In your original post, you state the &lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;SelectLayerByAttribute_management tool is "&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;an expensive transaction."&amp;nbsp; Assuming you mean expensive in terms of time, what are you using to time the tool and what are you comparing it against?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Generally, I stick with the arcpy functions and classes as much as possible and use the geoprocessing tools only when necessary or beneficial.&amp;nbsp; In this type of situation, i.e., getting the bounding extent of selected features or a subset of features, I find the geoprocessing tools are faster for most of the datasets I interact with regularly.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;I have had success using a mapping layer and the SelectLayerByAttribute_management tool:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def GetExtent(fc, sql):
&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr = arcpy.mapping.Layer(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", sql)
&amp;nbsp;&amp;nbsp;&amp;nbsp; return lyr.getSelectedExtent()&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Writing simple functions and using timeit on one of my datasets with ~250,000 records, I find using a map layer and SelectLayerByAttribute at least an order of magnitude faster than a search cursor.&amp;nbsp; I can't say for your datasets, but it might be worth trying the geoprocessing tools instead of relying on a search cursor.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 06:58:55 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2021-12-12T06:58:55Z</dc:date>
    <item>
      <title>Get Extent object for features returned by SearchCursor</title>
      <link>https://community.esri.com/t5/python-questions/get-extent-object-for-features-returned-by/m-p/724402#M56086</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What is a good way to get an extent object for the features returned by a da.SearchCursor with a where_clause applied? Certainly, I could apply a selection to the FeatureLayer and then use the getSelectedExtent method on the Layer object but frankly, I find SelectLayerByAttribute_management to be an expensive transaction. Add to this that I would also need to go back and clear the selection too. I just want to zoom to the extent of the returned features of the SearchCursor. Ideas?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14140852813432638" jivemacro_uid="_14140852813432638" modifiedtitle="true"&gt;
&lt;P&gt;with arcpy.da.SearchCursor(FeatureLayer, "SHAPE@", searchQuery) as rows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rowCount = 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rowCount = rowCount + 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print str(rowCount)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if rowCount == 0:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pythonaddins.MessageBox("No features found which meet criteria.", &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "ERROR: INVALID SEARCH CRITERIA", 0)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif rowCount == 1:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row[0].type == "point":&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extent = row[0].extent&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.extent = extent&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.scale = 5000&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del extent&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del rows&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Geometry is: " + str(row[0].type)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif rowCount &amp;gt; 1:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # so...now I have a bunch of features/rows returned..hmm&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # how to go about getting the full extent for these &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # returned features without applying a selection&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2014 17:31:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-extent-object-for-features-returned-by/m-p/724402#M56086</guid>
      <dc:creator>JohnDye</dc:creator>
      <dc:date>2014-10-23T17:31:08Z</dc:date>
    </item>
    <item>
      <title>Re: Get Extent object for features returned by SearchCursor</title>
      <link>https://community.esri.com/t5/python-questions/get-extent-object-for-features-returned-by/m-p/724403#M56087</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;just create a function within your script,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def GetExtents(extents):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; XMin = min([ext.XMin for ext in extents])&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; XMax = max([ext.XMax for ext in extents])&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; YMin = min([ext.YMin for ext in extents])&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; YMax = max([ext.YMax for ext in extents])&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return arcpy.Extents(XMin, YMin, XMax, YMax)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and within your main for the qualifying condition,&lt;/P&gt;&lt;P&gt;df.extent = GetExtents(extents)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2014 19:00:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-extent-object-for-features-returned-by/m-p/724403#M56087</guid>
      <dc:creator>ChrisPedrezuela</dc:creator>
      <dc:date>2014-10-23T19:00:15Z</dc:date>
    </item>
    <item>
      <title>Re: Get Extent object for features returned by SearchCursor</title>
      <link>https://community.esri.com/t5/python-questions/get-extent-object-for-features-returned-by/m-p/724404#M56088</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not sure I follow. I get what the function is doing, but I need to pass an extent object into your function. What I'm looking to do is get an extent for all of the records returned by a search cursor, so how would I pass the search cursor's returned records into the GetExtent function when it takes an extent object as it's parameter?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2014 19:17:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-extent-object-for-features-returned-by/m-p/724404#M56088</guid>
      <dc:creator>JohnDye</dc:creator>
      <dc:date>2014-10-23T19:17:13Z</dc:date>
    </item>
    <item>
      <title>Re: Get Extent object for features returned by SearchCursor</title>
      <link>https://community.esri.com/t5/python-questions/get-extent-object-for-features-returned-by/m-p/724405#M56089</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;sorry I wasn't clear. the extents parameter in my function is an actual list of all the returned rows from your main, so means the function requires you to create a list of all those extent objects.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

def GetExtents(extents):


&amp;nbsp;&amp;nbsp;&amp;nbsp; XMin = min([ext.XMin for ext in extents])
&amp;nbsp;&amp;nbsp;&amp;nbsp; XMax = max([ext.XMax for ext in extents])
&amp;nbsp;&amp;nbsp;&amp;nbsp; YMin = min([ext.YMin for ext in extents])
&amp;nbsp;&amp;nbsp;&amp;nbsp; YMax = max([ext.YMax for ext in extents])


&amp;nbsp;&amp;nbsp;&amp;nbsp; return arcpy.Extents(XMin, YMin, XMax, YMax)





extents = []


with arcpy.da.SearchCursor(lyr, field, query) as cur:


&amp;nbsp; for row in cur:


&amp;nbsp;&amp;nbsp;&amp;nbsp; extents.append(row[0].extent)





if len(extents) == 0:


&amp;nbsp; do something


elif len(extents) == 1:


&amp;nbsp; do something


elif len(extents) &amp;gt;1:


&amp;nbsp; df.extent = GetExtents(extents)

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:58:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-extent-object-for-features-returned-by/m-p/724405#M56089</guid>
      <dc:creator>ChrisPedrezuela</dc:creator>
      <dc:date>2021-12-12T06:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: Get Extent object for features returned by SearchCursor</title>
      <link>https://community.esri.com/t5/python-questions/get-extent-object-for-features-returned-by/m-p/724406#M56090</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ah, now I understand. Unfortunately I didn't see this until I had already solved my problem and came back to report my solution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I ended up doing was actually just building a multipoint geometry and then grabbing the extent of that geometry object.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14141006433024435" jivemacro_uid="_14141006433024435" modifiedtitle="true"&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif rowCount &amp;gt; 1:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row[0].type == 'point':&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array = arcpy.Array()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(FeatureLayer, "SHAPE@", searchQuery) as rows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array.add(row[0].trueCentroid)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; points = arcpy.Multipoint(array)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.extent = points.extent&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Geometry is: " + str(row[0].type)&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think your solution is probably a little more flexible in that it will account for any geometry type. Mine on the other hand is only going to work for points.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2014 21:44:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-extent-object-for-features-returned-by/m-p/724406#M56090</guid>
      <dc:creator>JohnDye</dc:creator>
      <dc:date>2014-10-23T21:44:38Z</dc:date>
    </item>
    <item>
      <title>Re: Get Extent object for features returned by SearchCursor</title>
      <link>https://community.esri.com/t5/python-questions/get-extent-object-for-features-returned-by/m-p/724407#M56091</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's my attempt:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_1414119658144147" jivemacro_uid="_1414119658144147" modifiedtitle="true"&gt;
&lt;P&gt;import arcpy&lt;/P&gt;
&lt;P&gt;def SelectedExtent(lyr):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; """Find extent of selected features"""&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; extents = []&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in arcpy.da.SearchCursor(lyr, "SHAPE@"): &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extents.append(row[0].extent)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if extents:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; XMin = min([e.XMin for e in extents]) &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; XMax = max([e.XMax for e in extents]) &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; YMin = min([e.YMin for e in extents]) &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; YMax = max([e.YMax for e in extents])&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return arcpy.Extent(XMin, YMin, XMax, YMax)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise Exception("No features in " + lyr)&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Oct 2014 03:02:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-extent-object-for-features-returned-by/m-p/724407#M56091</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2014-10-24T03:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: Get Extent object for features returned by SearchCursor</title>
      <link>https://community.esri.com/t5/python-questions/get-extent-object-for-features-returned-by/m-p/724408#M56092</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In your original post, you state the &lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;SelectLayerByAttribute_management tool is "&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;an expensive transaction."&amp;nbsp; Assuming you mean expensive in terms of time, what are you using to time the tool and what are you comparing it against?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Generally, I stick with the arcpy functions and classes as much as possible and use the geoprocessing tools only when necessary or beneficial.&amp;nbsp; In this type of situation, i.e., getting the bounding extent of selected features or a subset of features, I find the geoprocessing tools are faster for most of the datasets I interact with regularly.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;I have had success using a mapping layer and the SelectLayerByAttribute_management tool:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def GetExtent(fc, sql):
&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr = arcpy.mapping.Layer(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", sql)
&amp;nbsp;&amp;nbsp;&amp;nbsp; return lyr.getSelectedExtent()&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Writing simple functions and using timeit on one of my datasets with ~250,000 records, I find using a map layer and SelectLayerByAttribute at least an order of magnitude faster than a search cursor.&amp;nbsp; I can't say for your datasets, but it might be worth trying the geoprocessing tools instead of relying on a search cursor.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:58:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-extent-object-for-features-returned-by/m-p/724408#M56092</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-12T06:58:55Z</dc:date>
    </item>
  </channel>
</rss>

