<?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 by polygon - python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/select-by-polygon-python/m-p/442891#M34653</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You need to use some geoprocessing tools. Try the "SelectByAttribute" tool to select your polygon from the attribute table. You need to convert the attribute table to a feature layer to in order to make it selectable. Here's a peice from a script of mine that might help. It helps you select points in polygons, but the general idea of what you are looking to do is there:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Converts unselectable feature class into a selectable feature layer
gp.MakeFeatureLayer(POINT,"point")
gp.MakeFeatureLayer(POLYGON,"polygon")

rows = gp.SearchCursor("polygon")
row = rows.Next()

gp.AddMessage("Calculating Points in Polgons...")


try:

&amp;nbsp;&amp;nbsp;&amp;nbsp; while row:
&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; #gp.AddMessage(row.OBJECTID)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Select each record inside of the polygon feature class&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SelPoly = gp.SelectLayerByAttribute("polygon", "NEW_SELECTION", "\"OBJECTID\" =" + str(row.OBJECTID))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #gp.AddMessage(row.OBJECTID)
&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; # Select all the point that are inside of the polygon record
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SelPts = gp.SelectLayerByLocation("point", "WITHIN", SelPoly, 0, "NEW_SELECTION")
&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; # Count the points that are in each polygon
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GetCount = gp.GetCount_management(SelPts)
&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; # Calculate the ASSOC_PTS field with the counted points
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.CalculateField_management("polygon", "ASSOC_PTS", GetCount, "VB", "")

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Move to the next row&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.Next()
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 19:48:25 GMT</pubDate>
    <dc:creator>MikeMacRae</dc:creator>
    <dc:date>2021-12-11T19:48:25Z</dc:date>
    <item>
      <title>Select by polygon - python</title>
      <link>https://community.esri.com/t5/python-questions/select-by-polygon-python/m-p/442888#M34650</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I need to create a python script where the user can ???select by polygon??? and the selection is then created into a new feature class.&amp;nbsp; Do I need to use ArcObjects for this? I am currently using ArcGIS 10 and python, but don???t have much experience with ArcObjects. Doing this with a model is easy, but the user would like it to be automated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;kv&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 May 2011 16:58:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-polygon-python/m-p/442888#M34650</guid>
      <dc:creator>kristinavucic</dc:creator>
      <dc:date>2011-05-03T16:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: Select by polygon - python</title>
      <link>https://community.esri.com/t5/python-questions/select-by-polygon-python/m-p/442889#M34651</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;In ArcGIS 10, you can create a model or script tool with no parameters and put it on a toolbar. Then when you click the button it runs without any user interaction. I imagine this would work for you provided it was set up to run how the user expects it to without their interaction except for selecting the polygon feature and then clicking the button.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 May 2011 17:15:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-polygon-python/m-p/442889#M34651</guid>
      <dc:creator>LoganPugh</dc:creator>
      <dc:date>2011-05-03T17:15:22Z</dc:date>
    </item>
    <item>
      <title>Re: Select by polygon - python</title>
      <link>https://community.esri.com/t5/python-questions/select-by-polygon-python/m-p/442890#M34652</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;There is a datatype in the tool properties that allows you to sketch a polygon (or point or line) graphic that is passed into the script. You can create a featureclass from it. The data type is a featureset. You need a template defined in a layer file to use it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can sketch any type of polygon as in the draw tool, edit it and add attributes to fields defined in the template.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 May 2011 09:50:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-polygon-python/m-p/442890#M34652</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2011-05-09T09:50:03Z</dc:date>
    </item>
    <item>
      <title>Re: Select by polygon - python</title>
      <link>https://community.esri.com/t5/python-questions/select-by-polygon-python/m-p/442891#M34653</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You need to use some geoprocessing tools. Try the "SelectByAttribute" tool to select your polygon from the attribute table. You need to convert the attribute table to a feature layer to in order to make it selectable. Here's a peice from a script of mine that might help. It helps you select points in polygons, but the general idea of what you are looking to do is there:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Converts unselectable feature class into a selectable feature layer
gp.MakeFeatureLayer(POINT,"point")
gp.MakeFeatureLayer(POLYGON,"polygon")

rows = gp.SearchCursor("polygon")
row = rows.Next()

gp.AddMessage("Calculating Points in Polgons...")


try:

&amp;nbsp;&amp;nbsp;&amp;nbsp; while row:
&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; #gp.AddMessage(row.OBJECTID)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Select each record inside of the polygon feature class&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SelPoly = gp.SelectLayerByAttribute("polygon", "NEW_SELECTION", "\"OBJECTID\" =" + str(row.OBJECTID))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #gp.AddMessage(row.OBJECTID)
&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; # Select all the point that are inside of the polygon record
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SelPts = gp.SelectLayerByLocation("point", "WITHIN", SelPoly, 0, "NEW_SELECTION")
&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; # Count the points that are in each polygon
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GetCount = gp.GetCount_management(SelPts)
&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; # Calculate the ASSOC_PTS field with the counted points
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.CalculateField_management("polygon", "ASSOC_PTS", GetCount, "VB", "")

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Move to the next row&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.Next()
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:48:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-polygon-python/m-p/442891#M34653</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2021-12-11T19:48:25Z</dc:date>
    </item>
    <item>
      <title>Re: Select by polygon - python</title>
      <link>https://community.esri.com/t5/python-questions/select-by-polygon-python/m-p/442892#M34654</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you very much for your replies. I have used Feature Set as my input and it works perfectly.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 May 2011 15:23:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-polygon-python/m-p/442892#M34654</guid>
      <dc:creator>kristinavucic</dc:creator>
      <dc:date>2011-05-18T15:23:03Z</dc:date>
    </item>
  </channel>
</rss>

