<?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: Select features using onRectangle in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/select-features-using-onrectangle/m-p/658437#M51240</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;After you get your extent, to select the features in a layer named 'Stands' intersecting the extent rectangle, do this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument('CURRENT')
&amp;nbsp;&amp;nbsp;&amp;nbsp; df = mxd.activeDataFrame
&amp;nbsp;&amp;nbsp;&amp;nbsp; ext = df.extent
&amp;nbsp;&amp;nbsp;&amp;nbsp; lyrs = arcpy.mapping.ListLayers(mxd, "Stands", df)
&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyrs:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr = lyrs[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return

&amp;nbsp;&amp;nbsp;&amp;nbsp; a = arcpy.Array()
&amp;nbsp;&amp;nbsp;&amp;nbsp; a.add(ext.lowerLeft)
&amp;nbsp;&amp;nbsp;&amp;nbsp; a.add(ext.lowerRight)
&amp;nbsp;&amp;nbsp;&amp;nbsp; a.add(ext.upperRight)
&amp;nbsp;&amp;nbsp;&amp;nbsp; a.add(ext.upperLeft)
&amp;nbsp;&amp;nbsp;&amp;nbsp; a.add(ext.lowerLeft)
&amp;nbsp;&amp;nbsp;&amp;nbsp; thepoly = arcpy.Polygon(a)

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management('Stands', 'Intersect', thepoly, 0, 'New_Selection')

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can read more about SelectLayerByLocation in the online help.&amp;nbsp; But it sounds like you really don't want to select features as much as grab some attributes.&amp;nbsp; If that is the case, then I'd set up a search cursor, curse through the records, and if the shape of a feature intersects the poly we made above, grab the attributes of interest. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;good luck,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 03:51:44 GMT</pubDate>
    <dc:creator>MikeHunter</dc:creator>
    <dc:date>2021-12-12T03:51:44Z</dc:date>
    <item>
      <title>Select features using onRectangle</title>
      <link>https://community.esri.com/t5/python-questions/select-features-using-onrectangle/m-p/658436#M51239</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I found an interesting function to use in an add-in called onRectangle. I would like to use this to build a feature set and get values from fields.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
def __init__(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp; self.enabled = True
&amp;nbsp;&amp;nbsp;&amp;nbsp; self.cursor = 3
&amp;nbsp;&amp;nbsp;&amp;nbsp; self.shape = 'Rectangle'
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
def onRectangle(self, rectangle_geometry):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Occurs when the rectangle is drawn and the mouse button is released.
&amp;nbsp;&amp;nbsp;&amp;nbsp; The rectangle is a extent object."""

&amp;nbsp;&amp;nbsp;&amp;nbsp; extent = rectangle_geometry
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;Now that I have an extent how do I use it to select a feature or features and then get the values from field1, field2, etc...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Dec 2012 12:38:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-features-using-onrectangle/m-p/658436#M51239</guid>
      <dc:creator>HarryMcKenzie</dc:creator>
      <dc:date>2012-12-06T12:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: Select features using onRectangle</title>
      <link>https://community.esri.com/t5/python-questions/select-features-using-onrectangle/m-p/658437#M51240</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;After you get your extent, to select the features in a layer named 'Stands' intersecting the extent rectangle, do this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument('CURRENT')
&amp;nbsp;&amp;nbsp;&amp;nbsp; df = mxd.activeDataFrame
&amp;nbsp;&amp;nbsp;&amp;nbsp; ext = df.extent
&amp;nbsp;&amp;nbsp;&amp;nbsp; lyrs = arcpy.mapping.ListLayers(mxd, "Stands", df)
&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyrs:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr = lyrs[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return

&amp;nbsp;&amp;nbsp;&amp;nbsp; a = arcpy.Array()
&amp;nbsp;&amp;nbsp;&amp;nbsp; a.add(ext.lowerLeft)
&amp;nbsp;&amp;nbsp;&amp;nbsp; a.add(ext.lowerRight)
&amp;nbsp;&amp;nbsp;&amp;nbsp; a.add(ext.upperRight)
&amp;nbsp;&amp;nbsp;&amp;nbsp; a.add(ext.upperLeft)
&amp;nbsp;&amp;nbsp;&amp;nbsp; a.add(ext.lowerLeft)
&amp;nbsp;&amp;nbsp;&amp;nbsp; thepoly = arcpy.Polygon(a)

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management('Stands', 'Intersect', thepoly, 0, 'New_Selection')

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can read more about SelectLayerByLocation in the online help.&amp;nbsp; But it sounds like you really don't want to select features as much as grab some attributes.&amp;nbsp; If that is the case, then I'd set up a search cursor, curse through the records, and if the shape of a feature intersects the poly we made above, grab the attributes of interest. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;good luck,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:51:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-features-using-onrectangle/m-p/658437#M51240</guid>
      <dc:creator>MikeHunter</dc:creator>
      <dc:date>2021-12-12T03:51:44Z</dc:date>
    </item>
  </channel>
</rss>

