<?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 How to do a select by location using a hosted layer? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-do-a-select-by-location-using-a-hosted/m-p/741915#M57346</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am looking to select/retrieve the polygon, based on a hosted layer, that contains a given point. The&amp;nbsp;SelectLayerByLocation on my test works for local .gdb feature classes. I was not able to make it work using an online FeatureLayer. This is the error I get:&amp;nbsp;RuntimeError: Object: Error in executing tool&lt;/P&gt;&lt;P&gt;I appreciate any ideas...&lt;/P&gt;&lt;P&gt;Here is a code example I have:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="font-size: 13px;"&gt;&lt;SPAN style="color: #d73a49;"&gt;import &lt;/SPAN&gt;arcpy&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt;&lt;SPAN style="color: #d73a49;"&gt;from &lt;/SPAN&gt;arcgis.gis &lt;SPAN style="color: #d73a49;"&gt;import &lt;/SPAN&gt;GIS&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt;&lt;SPAN style="color: #d73a49;"&gt;from &lt;/SPAN&gt;arcgis.features &lt;SPAN style="color: #d73a49;"&gt;import &lt;/SPAN&gt;FeatureLayer&lt;/SPAN&gt;

&lt;SPAN style="font-size: 13px;"&gt;gis &lt;SPAN style="color: #d73a49;"&gt;= &lt;/SPAN&gt;&lt;SPAN style="color: #6f42c1;"&gt;GIS&lt;/SPAN&gt;()&lt;/SPAN&gt;
#load online layer
&lt;SPAN style="font-size: 13px;"&gt;CaLayer &lt;SPAN style="color: #d73a49;"&gt;= &lt;/SPAN&gt;&lt;SPAN style="color: #6f42c1;"&gt;FeatureLayer&lt;/SPAN&gt;(&lt;SPAN style="color: #032f62;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;https://services.arcgis.com/BLN4oKB0N1YSgvY8/arcgis/rest/services/Counties_in_California/FeatureServer/0&lt;/SPAN&gt;&lt;SPAN style="color: #032f62;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;, &lt;/SPAN&gt;gis)&lt;/SPAN&gt;
#verify the variable has content
&lt;SPAN style="font-size: 13px;"&gt;&lt;SPAN style="color: #6f42c1;"&gt;print&lt;/SPAN&gt;(CaLayer)&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt;&lt;SPAN style="color: #6f42c1;"&gt;print&lt;/SPAN&gt;(&lt;SPAN style="color: #6f42c1;"&gt;type&lt;/SPAN&gt;(CaLayer))&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt;&lt;SPAN style="color: #6f42c1;"&gt;print&lt;/SPAN&gt;(CaLayer.properties.capabilities)&lt;/SPAN&gt;
#create a point
&lt;SPAN style="font-size: 13px;"&gt;point &lt;SPAN style="color: #d73a49;"&gt;= &lt;/SPAN&gt;arcpy.&lt;SPAN style="color: #6f42c1;"&gt;Point&lt;/SPAN&gt;(&lt;SPAN style="color: #d73a49;"&gt;-&lt;/SPAN&gt;&lt;SPAN style="color: #005cc5;"&gt;117.182&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #005cc5;"&gt;34.055&lt;/SPAN&gt;)&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt;ptGeometry &lt;SPAN style="color: #d73a49;"&gt;= &lt;/SPAN&gt;arcpy.&lt;SPAN style="color: #6f42c1;"&gt;PointGeometry&lt;/SPAN&gt;(point&lt;SPAN style="color: #808080;"&gt;, &lt;/SPAN&gt;arcpy.&lt;SPAN style="color: #6f42c1;"&gt;SpatialReference&lt;/SPAN&gt;(&lt;SPAN style="color: #005cc5;"&gt;4326&lt;/SPAN&gt;))&lt;/SPAN&gt;
#try to run &lt;SPAN style="color: #6f42c1; font-size: 13px; "&gt;SelectLayerByLocation&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt;selection = arcpy.management.&lt;SPAN style="color: #6f42c1;"&gt;SelectLayerByLocation&lt;/SPAN&gt;(CaLayer&lt;SPAN style="color: #808080;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #032f62;"&gt;"CONTAINS"&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;, &lt;/SPAN&gt;ptGeometry)&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 07:34:54 GMT</pubDate>
    <dc:creator>EdirleiSantos</dc:creator>
    <dc:date>2021-12-12T07:34:54Z</dc:date>
    <item>
      <title>How to do a select by location using a hosted layer?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-do-a-select-by-location-using-a-hosted/m-p/741915#M57346</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am looking to select/retrieve the polygon, based on a hosted layer, that contains a given point. The&amp;nbsp;SelectLayerByLocation on my test works for local .gdb feature classes. I was not able to make it work using an online FeatureLayer. This is the error I get:&amp;nbsp;RuntimeError: Object: Error in executing tool&lt;/P&gt;&lt;P&gt;I appreciate any ideas...&lt;/P&gt;&lt;P&gt;Here is a code example I have:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="font-size: 13px;"&gt;&lt;SPAN style="color: #d73a49;"&gt;import &lt;/SPAN&gt;arcpy&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt;&lt;SPAN style="color: #d73a49;"&gt;from &lt;/SPAN&gt;arcgis.gis &lt;SPAN style="color: #d73a49;"&gt;import &lt;/SPAN&gt;GIS&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt;&lt;SPAN style="color: #d73a49;"&gt;from &lt;/SPAN&gt;arcgis.features &lt;SPAN style="color: #d73a49;"&gt;import &lt;/SPAN&gt;FeatureLayer&lt;/SPAN&gt;

&lt;SPAN style="font-size: 13px;"&gt;gis &lt;SPAN style="color: #d73a49;"&gt;= &lt;/SPAN&gt;&lt;SPAN style="color: #6f42c1;"&gt;GIS&lt;/SPAN&gt;()&lt;/SPAN&gt;
#load online layer
&lt;SPAN style="font-size: 13px;"&gt;CaLayer &lt;SPAN style="color: #d73a49;"&gt;= &lt;/SPAN&gt;&lt;SPAN style="color: #6f42c1;"&gt;FeatureLayer&lt;/SPAN&gt;(&lt;SPAN style="color: #032f62;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;https://services.arcgis.com/BLN4oKB0N1YSgvY8/arcgis/rest/services/Counties_in_California/FeatureServer/0&lt;/SPAN&gt;&lt;SPAN style="color: #032f62;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;, &lt;/SPAN&gt;gis)&lt;/SPAN&gt;
#verify the variable has content
&lt;SPAN style="font-size: 13px;"&gt;&lt;SPAN style="color: #6f42c1;"&gt;print&lt;/SPAN&gt;(CaLayer)&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt;&lt;SPAN style="color: #6f42c1;"&gt;print&lt;/SPAN&gt;(&lt;SPAN style="color: #6f42c1;"&gt;type&lt;/SPAN&gt;(CaLayer))&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt;&lt;SPAN style="color: #6f42c1;"&gt;print&lt;/SPAN&gt;(CaLayer.properties.capabilities)&lt;/SPAN&gt;
#create a point
&lt;SPAN style="font-size: 13px;"&gt;point &lt;SPAN style="color: #d73a49;"&gt;= &lt;/SPAN&gt;arcpy.&lt;SPAN style="color: #6f42c1;"&gt;Point&lt;/SPAN&gt;(&lt;SPAN style="color: #d73a49;"&gt;-&lt;/SPAN&gt;&lt;SPAN style="color: #005cc5;"&gt;117.182&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #005cc5;"&gt;34.055&lt;/SPAN&gt;)&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt;ptGeometry &lt;SPAN style="color: #d73a49;"&gt;= &lt;/SPAN&gt;arcpy.&lt;SPAN style="color: #6f42c1;"&gt;PointGeometry&lt;/SPAN&gt;(point&lt;SPAN style="color: #808080;"&gt;, &lt;/SPAN&gt;arcpy.&lt;SPAN style="color: #6f42c1;"&gt;SpatialReference&lt;/SPAN&gt;(&lt;SPAN style="color: #005cc5;"&gt;4326&lt;/SPAN&gt;))&lt;/SPAN&gt;
#try to run &lt;SPAN style="color: #6f42c1; font-size: 13px; "&gt;SelectLayerByLocation&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt;selection = arcpy.management.&lt;SPAN style="color: #6f42c1;"&gt;SelectLayerByLocation&lt;/SPAN&gt;(CaLayer&lt;SPAN style="color: #808080;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #032f62;"&gt;"CONTAINS"&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;, &lt;/SPAN&gt;ptGeometry)&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:34:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-do-a-select-by-location-using-a-hosted/m-p/741915#M57346</guid>
      <dc:creator>EdirleiSantos</dc:creator>
      <dc:date>2021-12-12T07:34:54Z</dc:date>
    </item>
  </channel>
</rss>

