<?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: Selecting points not within polygons in arcpy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/selecting-points-not-within-polygons-in-arcpy/m-p/1498999#M70934</link>
    <description>&lt;P&gt;You are running your python on &lt;STRONG&gt;feature class&lt;/STRONG&gt; inputs, not feature layers (which is what you're running the tool in Pro on). A feature layer is a temporary construct within a Pro session which gives you a view, symbology etc of your feature class.&lt;BR /&gt;&lt;BR /&gt;Use the&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/make-feature-layer.htm" target="_self"&gt;Make Feature Layer tool&lt;/A&gt;&amp;nbsp;first in your script, then use the two layers you create as your inputs for the select by location and I suspect you will have more success.&lt;BR /&gt;&lt;BR /&gt;Or (as I can see you've attached it to a toolbox) make the inputs for the tool "feature layers" allowing you to drag and drop from your table of contents&lt;/P&gt;</description>
    <pubDate>Fri, 28 Jun 2024 12:25:46 GMT</pubDate>
    <dc:creator>RichardHowe</dc:creator>
    <dc:date>2024-06-28T12:25:46Z</dc:date>
    <item>
      <title>Selecting points not within polygons in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/selecting-points-not-within-polygons-in-arcpy/m-p/1498992#M70933</link>
      <description>&lt;P&gt;Dear community,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having problems selecting points from a layer which are not within another polygon layer. I have tried using&amp;nbsp;&lt;SPAN&gt;arcpy&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;SelectLayerByLocation_management&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;point&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'WITHIN'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;poly&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;''&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'NEW_SELECTION'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'INVERT'&lt;/SPAN&gt;&lt;SPAN&gt;), but it has not yielded the desired results.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;To test this functionality, I have created the MWE below.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

def main():

    arcpy.env.workspace = arcpy.env.scratchGDB
    arcpy.env.overwriteOutput = True

    poly = 'test.gdb/test_poly'
    point = 'test.gdb/test_point'

    arcpy.SelectLayerByLocation_management(point, 'WITHIN', poly, '', 'NEW_SELECTION', 'INVERT')
    
    point_select = 'point_select'
    arcpy.CopyFeatures_management(point, point_select)

    arcpy.SelectLayerByAttribute_management(point, selection_type='CLEAR_SELECTION')

if __name__ == "__main__":
    main()&lt;/LI-CODE&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;For which I also have created a new database with a point (5 features) and polygon (1 features) layer:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="blob_2-1719575567538.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/108248iBD7950C5EA4BBB07/image-size/medium?v=v2&amp;amp;px=400" role="button" title="blob_2-1719575567538.png" alt="blob_2-1719575567538.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have also created a new tool to test this with, for which I am getting the output (with some small print statements added):&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="blob_1-1719575418697.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/108247i30CB21ED8547C438/image-size/medium?v=v2&amp;amp;px=400" role="button" title="blob_1-1719575418697.png" alt="blob_1-1719575418697.png" /&gt;&lt;/span&gt;&lt;P&gt;Which suggests that no selection is being done. Using the Select By Location tool within ArcGIS Pro (the same equivalent?) the selection works:&lt;/P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="blob_4-1719575781576.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/108250iBB9830CF48E4119C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="blob_4-1719575781576.png" alt="blob_4-1719575781576.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="blob_3-1719575741393.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/108249i4FB4731CEF47D5D2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="blob_3-1719575741393.png" alt="blob_3-1719575741393.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Things I have tried:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Substituting the operation ('INTERSECT', 'COMPLETELY_WITHIN')&lt;/LI&gt;&lt;LI&gt;Clearing the cache (Project &amp;gt; Options &amp;gt; Application &amp;gt; Display &amp;gt; Local Cache &amp;gt; Clear Cache Now)&lt;/LI&gt;&lt;LI&gt;Restarting ArcGIS / reloading tool&lt;/LI&gt;&lt;LI&gt;Clearing / not clearing the selection after copying features&lt;/LI&gt;&lt;LI&gt;Using layers in scratch.gdb / actual database&lt;/LI&gt;&lt;LI&gt;Setting the method arguments using their names (in_layer=..., overlap_type=..., etc.)&lt;/LI&gt;&lt;LI&gt;Switching 'INVERT' / 'NOT_INVERT' but none of them affect the results, i.e. no selection&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Am I misunderstanding how this method works, or is there some other explanation for the selection not working?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 28 Jun 2024 12:12:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-points-not-within-polygons-in-arcpy/m-p/1498992#M70933</guid>
      <dc:creator>blob</dc:creator>
      <dc:date>2024-06-28T12:12:34Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting points not within polygons in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/selecting-points-not-within-polygons-in-arcpy/m-p/1498999#M70934</link>
      <description>&lt;P&gt;You are running your python on &lt;STRONG&gt;feature class&lt;/STRONG&gt; inputs, not feature layers (which is what you're running the tool in Pro on). A feature layer is a temporary construct within a Pro session which gives you a view, symbology etc of your feature class.&lt;BR /&gt;&lt;BR /&gt;Use the&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/make-feature-layer.htm" target="_self"&gt;Make Feature Layer tool&lt;/A&gt;&amp;nbsp;first in your script, then use the two layers you create as your inputs for the select by location and I suspect you will have more success.&lt;BR /&gt;&lt;BR /&gt;Or (as I can see you've attached it to a toolbox) make the inputs for the tool "feature layers" allowing you to drag and drop from your table of contents&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2024 12:25:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-points-not-within-polygons-in-arcpy/m-p/1498999#M70934</guid>
      <dc:creator>RichardHowe</dc:creator>
      <dc:date>2024-06-28T12:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting points not within polygons in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/selecting-points-not-within-polygons-in-arcpy/m-p/1499010#M70935</link>
      <description>&lt;P&gt;That's a good point. I'd also try assigning the selection to a variable to pass into copy(). See Lines 11 and 14.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

def main():

    arcpy.env.workspace = arcpy.env.scratchGDB
    arcpy.env.overwriteOutput = True

    poly = 'test.gdb/test_poly'
    point = 'test.gdb/test_point'

    sel =arcpy.SelectLayerByLocation_management(point, 'WITHIN', poly, '', 'NEW_SELECTION', 'INVERT')
    
    point_select = 'point_select'
    arcpy.CopyFeatures_management(sel, point_select)
    #tbh I'm not sure this is needed
    #arcpy.SelectLayerByAttribute_management(point, selection_type='CLEAR_SELECTION')

if __name__ == "__main__":
    main()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2024 12:55:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-points-not-within-polygons-in-arcpy/m-p/1499010#M70935</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2024-06-28T12:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting points not within polygons in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/selecting-points-not-within-polygons-in-arcpy/m-p/1499656#M70941</link>
      <description>&lt;P&gt;This worked, thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2024 06:35:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-points-not-within-polygons-in-arcpy/m-p/1499656#M70941</guid>
      <dc:creator>blob</dc:creator>
      <dc:date>2024-07-01T06:35:34Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting points not within polygons in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/selecting-points-not-within-polygons-in-arcpy/m-p/1499658#M70942</link>
      <description>&lt;P&gt;Good suggestion, I will implement this as well!&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2024 06:36:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selecting-points-not-within-polygons-in-arcpy/m-p/1499658#M70942</guid>
      <dc:creator>blob</dc:creator>
      <dc:date>2024-07-01T06:36:07Z</dc:date>
    </item>
  </channel>
</rss>

