<?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 Select by location not working on in_memory layer in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/select-by-location-not-working-on-in-memory-layer/m-p/138049#M10797</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;A coworker of my produced a great model and asked me to convert it to Python for him. The python script is failing at the same point each time I try to use it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It is unable to run the following command:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;gt;&amp;gt;&amp;gt; arcpy.SelectLayerByLocation_management('in_memory\\mergedStreetsPolygons', "COMPLETELY_WITHIN", outputGDB + '\\mtdbStreetBuffer', "", "NEW_SELECTION")&amp;nbsp; Traceback (most recent call last): &amp;nbsp; File "&amp;lt;pyshell#15&amp;gt;", line 1, in &amp;lt;module&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management('in_memory\\mergedStreetsPolygons', "COMPLETELY_WITHIN", outputGDB + '\\mtdbStreetBuffer', "", "NEW_SELECTION") &amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\management.py", line 6559, in SelectLayerByLocation &amp;nbsp;&amp;nbsp;&amp;nbsp; raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000368: Invalid input data. Failed to execute (SelectLayerByLocation).&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The "COMPLETELY_WITHIN" selection method requires that the selecting feature be of 'polygon' type, so I checked that:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;gt;&amp;gt;&amp;gt; arcpy.Describe('in_memory\\mtdbStreetBuffer').shapeType u'Polygon'&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I saved both of the layers as Feature Classes in a File GDB.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;gt;&amp;gt;&amp;gt; arcpy.CopyFeatures_management('in_memory\\mergedStreetsPolygons', outputGDB + '\\mergedStreetsPolygon') &amp;lt;Result '..path\suppressed..gdb\\mergedStreetsPolygon'&amp;gt; &amp;gt;&amp;gt;&amp;gt; arcpy.CopyFeatures_management('in_memory\\mtdbStreetBuffer', outputGDB + '\\mtdbStreetBuffer') &amp;lt;Result '..path\suppressed..gdb\\mtdbStreetBuffer'&amp;gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;*I blocked off the path to the GDB because it divulges more information about our servers than I should post on the forum.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I brought those features into ArcMap and used Arctoolbox to run the selection and it worked.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Using the python immediate window in ArcMap also worked.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So does anyone have any idea why the selection will not work 'in_memory'?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Other similar lines of code within the same script are working properly, just not this one.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 15 Aug 2013 13:57:09 GMT</pubDate>
    <dc:creator>PatrickJurgens</dc:creator>
    <dc:date>2013-08-15T13:57:09Z</dc:date>
    <item>
      <title>Select by location not working on in_memory layer</title>
      <link>https://community.esri.com/t5/python-questions/select-by-location-not-working-on-in-memory-layer/m-p/138049#M10797</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;A coworker of my produced a great model and asked me to convert it to Python for him. The python script is failing at the same point each time I try to use it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It is unable to run the following command:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;gt;&amp;gt;&amp;gt; arcpy.SelectLayerByLocation_management('in_memory\\mergedStreetsPolygons', "COMPLETELY_WITHIN", outputGDB + '\\mtdbStreetBuffer', "", "NEW_SELECTION")&amp;nbsp; Traceback (most recent call last): &amp;nbsp; File "&amp;lt;pyshell#15&amp;gt;", line 1, in &amp;lt;module&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management('in_memory\\mergedStreetsPolygons', "COMPLETELY_WITHIN", outputGDB + '\\mtdbStreetBuffer', "", "NEW_SELECTION") &amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\management.py", line 6559, in SelectLayerByLocation &amp;nbsp;&amp;nbsp;&amp;nbsp; raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000368: Invalid input data. Failed to execute (SelectLayerByLocation).&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The "COMPLETELY_WITHIN" selection method requires that the selecting feature be of 'polygon' type, so I checked that:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;gt;&amp;gt;&amp;gt; arcpy.Describe('in_memory\\mtdbStreetBuffer').shapeType u'Polygon'&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I saved both of the layers as Feature Classes in a File GDB.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;gt;&amp;gt;&amp;gt; arcpy.CopyFeatures_management('in_memory\\mergedStreetsPolygons', outputGDB + '\\mergedStreetsPolygon') &amp;lt;Result '..path\suppressed..gdb\\mergedStreetsPolygon'&amp;gt; &amp;gt;&amp;gt;&amp;gt; arcpy.CopyFeatures_management('in_memory\\mtdbStreetBuffer', outputGDB + '\\mtdbStreetBuffer') &amp;lt;Result '..path\suppressed..gdb\\mtdbStreetBuffer'&amp;gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;*I blocked off the path to the GDB because it divulges more information about our servers than I should post on the forum.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I brought those features into ArcMap and used Arctoolbox to run the selection and it worked.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Using the python immediate window in ArcMap also worked.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So does anyone have any idea why the selection will not work 'in_memory'?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Other similar lines of code within the same script are working properly, just not this one.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Aug 2013 13:57:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-location-not-working-on-in-memory-layer/m-p/138049#M10797</guid>
      <dc:creator>PatrickJurgens</dc:creator>
      <dc:date>2013-08-15T13:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: Select by location not working on in_memory layer</title>
      <link>https://community.esri.com/t5/python-questions/select-by-location-not-working-on-in-memory-layer/m-p/138050#M10798</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I solved this problem by back tracking.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In case other people stumble on this post while searching for their own solution here is what happened:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The 'in_layer' that I was using ('in_memery\\mergedStreetsPolygons') was not actually a layer, it was an in_memory feature class.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It originated from this command which I thought would output as a layer:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;arcpy.FeatureToPolygon_management('in_memory\\mergedStreets', 'in_memory\\mergedStreetsPolygons', "", "ATTRIBUTES", "")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried to modify the command to force it to output as a layer and that did not work, I guess it is only able to output to Feature Class:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;gt;&amp;gt;&amp;gt; arcpy.SelectLayerByLocation_management('in_memory\\mergedStreetsPolygons', "COMPLETELY_WITHIN", 'in_memory\\mtdbStreetBuffer.lyr', "", "NEW_SELECTION")&amp;nbsp; Traceback (most recent call last): &amp;nbsp; File "&amp;lt;pyshell#23&amp;gt;", line 1, in &amp;lt;module&amp;gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management('in_memory\\mergedStreetsPolygons', "COMPLETELY_WITHIN", 'in_memory\\mtdbStreetBuffer.lyr', "", "NEW_SELECTION") &amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\management.py", line 6559, in SelectLayerByLocation &amp;nbsp;&amp;nbsp;&amp;nbsp; raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000368: Invalid input data. ERROR 000732: Selecting Features: Dataset in_memory\mtdbStreetBuffer.lyr does not exist or is not supported Failed to execute (SelectLayerByLocation).&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;So I just added a line to convert it to a Layer and used the new layer name for the in_layer parameter. It worked:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;gt;&amp;gt;&amp;gt; arcpy.MakeFeatureLayer_management('in_memory\\mergedStreetsPolygons', 'in_memory\\mergedStreetsPolygons.lyr') &amp;lt;Result 'in_memory\\mergedStreetsPolygons.lyr'&amp;gt; &amp;gt;&amp;gt;&amp;gt; arcpy.SelectLayerByLocation_management('in_memory\\mergedStreetsPolygons.lyr', "COMPLETELY_WITHIN", 'in_memory\\mtdbStreetBuffer', "", "NEW_SELECTION") &amp;lt;Result 'in_memory\\mergedStreetsPolygons.lyr'&amp;gt;&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;Of course the on disk copies that I made (for trouble shooting) worked okay in ArcMap because when I brought them into the map it made layers of them.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Just a quick reminder, if you do something like this to fix your code make sure that all future commands that referenced the old 'layer' [technically it wasn't a layer, hence the error message] get updated to use the new one...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Aug 2013 14:31:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-location-not-working-on-in-memory-layer/m-p/138050#M10798</guid>
      <dc:creator>PatrickJurgens</dc:creator>
      <dc:date>2013-08-15T14:31:42Z</dc:date>
    </item>
    <item>
      <title>Re: Select by location not working on in_memory layer</title>
      <link>https://community.esri.com/t5/python-questions/select-by-location-not-working-on-in-memory-layer/m-p/138051#M10799</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;SelectLayerByLocation works with &lt;/SPAN&gt;&lt;STRONG&gt;FeatureLayers&lt;/STRONG&gt;&lt;SPAN&gt;, your code is referencing an in-memory &lt;/SPAN&gt;&lt;STRONG&gt;FeatureClass&lt;/STRONG&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You need to create a FeatureLayer for this before you call SelectLayerByLocation&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.MakeFeatureLayer_management('in_memory\\mergedStreetsPolygons',"StreetPolygonFeatureLayer")

arcpy.SelectLayerByLocation_management("StreetPolygonFeatureLayer", "COMPLETELY_WITHIN", 'in_memory\\mtdbStreetBuffer.lyr', "", "NEW_SELECTION")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:39:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-location-not-working-on-in-memory-layer/m-p/138051#M10799</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2021-12-11T07:39:28Z</dc:date>
    </item>
  </channel>
</rss>

