<?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: Python Error: arcpy.SelectLayerByLocation_management in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-error-arcpy-selectlayerbylocation/m-p/580031#M45489</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;THANKS!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 30 Sep 2016 15:33:06 GMT</pubDate>
    <dc:creator>JerryGarcia</dc:creator>
    <dc:date>2016-09-30T15:33:06Z</dc:date>
    <item>
      <title>Python Error: arcpy.SelectLayerByLocation_management</title>
      <link>https://community.esri.com/t5/python-questions/python-error-arcpy-selectlayerbylocation/m-p/580027#M45485</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG&gt;See screen shot.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Any suggestions?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Thanks!!!&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;wk=r'C:\Users\Administrator\AppData\Roaming\Esri\Desktop10.3\ArcCatalog\GIS DataCreator.sde'&lt;/P&gt;&lt;P&gt;arcpy.env.workspace=wk&lt;/P&gt;&lt;P&gt;print arcpy.env.workspace&lt;/P&gt;&lt;P&gt;fcCounties = "GIS.DATACREATOR.counties"&lt;BR /&gt;fieldsCounties = ['OBJECTID_1', 'Shape', 'NAME']&lt;BR /&gt;print arcpy.Exists(fcCounties)&lt;/P&gt;&lt;P&gt;fcSections = "GIS.DATACREATOR.sections_test"&lt;BR /&gt;fieldsSections = ['OBJECTID', 'Shape', 'county']&lt;BR /&gt;print arcpy.Exists(fcSections)&lt;BR /&gt; &lt;BR /&gt;arcpy.MakeFeatureLayer_management(fcSections, 'sections_lyr')&lt;BR /&gt;arcpy.MakeFeatureLayer_management(fcCounties, 'counties_lyr')&lt;/P&gt;&lt;P&gt;with arcpy.da.SearchCursor('counties_lyr', fieldsCounties) as cursor:&lt;BR /&gt; for row in cursor:&lt;BR /&gt; print row[1]&lt;BR /&gt; arcpy.SelectLayerByLocation_management('sections_lyr', row[1])&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;----------&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Python 2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)] on win32&lt;BR /&gt;Type "copyright", "credits" or "license()" for more information.&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; ================================ RESTART ================================&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt; &lt;BR /&gt;C:\Users\Administrator\AppData\Roaming\ESRI\Desktop10.3\ArcCatalog\GIS DataCreator.sde&lt;BR /&gt;True&lt;BR /&gt;True&lt;BR /&gt;(-9645043.375313655, 3833831.999483527)&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt; File "E:\Python\relateCopyCounties.py", line 23, in &amp;lt;module&amp;gt;&lt;BR /&gt; arcpy.SelectLayerByLocation_management('sections_lyr', row[1])&lt;BR /&gt; File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\management.py", line 7359, in SelectLayerByLocation&lt;BR /&gt; raise e&lt;BR /&gt;RuntimeError: Object: Error in executing tool&lt;BR /&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Sep 2016 11:52:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-error-arcpy-selectlayerbylocation/m-p/580027#M45485</guid>
      <dc:creator>JerryGarcia</dc:creator>
      <dc:date>2016-09-30T11:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: Python Error: arcpy.SelectLayerByLocation_management</title>
      <link>https://community.esri.com/t5/python-questions/python-error-arcpy-selectlayerbylocation/m-p/580028#M45486</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Take a look at the parameters for the tool.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Select Layer By Location&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;A class="link-bare" href="http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/select-layer-by-location.htm" title="http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/select-layer-by-location.htm"&gt;http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/select-layer-by-location.htm&lt;/A&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that the second parameter is&amp;nbsp;&lt;STRONG&gt;"overlap_type" &lt;/STRONG&gt;(e.g. INTERSECT, CONTAINS, etc.)&amp;nbsp;and you're supplying row[1], which is a tuple&amp;nbsp;representation of the geometry with the value&amp;nbsp;&lt;SPAN style="background-color: #ffffff;"&gt;(-9645043.375313655, 3833831.999483527).&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="236931" alt="" class="image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/236931_sss.png" style="width: 620px; height: 108px;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-2 jive-image" src="https://community.esri.com/legacyfs/online/236932_rrr.png" style="width: 862px; height: 417px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Sep 2016 13:11:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-error-arcpy-selectlayerbylocation/m-p/580028#M45486</guid>
      <dc:creator>FreddieGibson</dc:creator>
      <dc:date>2016-09-30T13:11:03Z</dc:date>
    </item>
    <item>
      <title>Re: Python Error: arcpy.SelectLayerByLocation_management</title>
      <link>https://community.esri.com/t5/python-questions/python-error-arcpy-selectlayerbylocation/m-p/580029#M45487</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks. &amp;nbsp;I was messing around with the parameters. &amp;nbsp;This is a mistake. &amp;nbsp;I get the same error when adding {overlap_type}:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.SelectLayerByLocation_management('sections_lyr', '&lt;STRONG&gt;INTERSECT&lt;/STRONG&gt;', row[1])&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-1 jive-image j-img-original" src="/legacyfs/online/236936_python error2.png" style="width: 620px; height: 737px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Sep 2016 13:24:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-error-arcpy-selectlayerbylocation/m-p/580029#M45487</guid>
      <dc:creator>JerryGarcia</dc:creator>
      <dc:date>2016-09-30T13:24:29Z</dc:date>
    </item>
    <item>
      <title>Re: Python Error: arcpy.SelectLayerByLocation_management</title>
      <link>https://community.esri.com/t5/python-questions/python-error-arcpy-selectlayerbylocation/m-p/580030#M45488</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Take a look at&amp;nbsp;the example I sent in my previous message. Your problem is that you need to provide the 3rd parameter as a feature class or a geometry object. By default the da cursor will return geometry as a tuple. You will want to use the &lt;A href="mailto:Shape@" rel="nofollow noopener noreferrer" target="_blank"&gt;Shape@ &lt;/A&gt;token to have it return the geometry object.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just to provide a little more detail&amp;nbsp;I've also included my logic below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;# Example 1 &lt;/SPAN&gt;
geom &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; next&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"fnet"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"SHAPE"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;management&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SelectLayerByLocation&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"fnet"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"INTERSECT"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; geom&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="string token"&gt;''' In the above example "SHAPE" returns (2124.3204345703125, 3.0001017252604063) '''&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# Example 2&lt;/SPAN&gt;
geom &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; next&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"fnet"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"SHAPE@XY"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;management&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SelectLayerByLocation&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"fnet"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"INTERSECT"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; geom&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="string token"&gt;''' In the above example "SHAPE@XY" returns (2124.3204345703125, 3.0001017252604063) '''&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# Example 3 &lt;/SPAN&gt;
geom &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; next&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"fnet"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"SHAPE@"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;management&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SelectLayerByLocation&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"fnet"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"INTERSECT"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; geom&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="string token"&gt;''' In the above example "SHAPE@" returns &amp;lt;Polygon object at 0x2382fcf0[0x2382f3e0]&amp;gt; '''&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the above examples note what is returned from the cursor. If you were to run each of these expressions you'd not that only the third one works, whereas the first two return the following exception.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;Runtime error &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;Traceback (most recent call last):&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt; File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt; File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\management.py", line 7320, in SelectLayerByLocation&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt; raise e&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;RuntimeError: Object: Error in executing tool&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:56:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-error-arcpy-selectlayerbylocation/m-p/580030#M45488</guid>
      <dc:creator>FreddieGibson</dc:creator>
      <dc:date>2021-12-12T00:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: Python Error: arcpy.SelectLayerByLocation_management</title>
      <link>https://community.esri.com/t5/python-questions/python-error-arcpy-selectlayerbylocation/m-p/580031#M45489</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;THANKS!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Sep 2016 15:33:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-error-arcpy-selectlayerbylocation/m-p/580031#M45489</guid>
      <dc:creator>JerryGarcia</dc:creator>
      <dc:date>2016-09-30T15:33:06Z</dc:date>
    </item>
  </channel>
</rss>

