How to do a select by location using a hosted layer?

05-17-2020 05:43 PM
New Contributor II

I am looking to select/retrieve the polygon, based on a hosted layer, that contains a given point. The 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: RuntimeError: Object: Error in executing tool

I appreciate any ideas...

Here is a code example I have:

import arcpy
from arcgis.gis import GIS
from arcgis.features import FeatureLayer

gis = GIS()
#load online layer
CaLayer = FeatureLayer("", gis)
#verify the variable has content
#create a point
point = arcpy.Point(-117.182, 34.055)
ptGeometry = arcpy.PointGeometry(point, arcpy.SpatialReference(4326))
#try to run SelectLayerByLocation
selection =, "CONTAINS", ptGeometry)
0 Kudos
0 Replies