SelectLayerByLocation_management fails for unknown reason

726
3
Jump to solution
09-02-2021 09:50 AM
Labels (3)
ChuckBenton
Occasional Contributor

I have an ArcGIS hosted feature layer, and want to make a selection based on a lat/lon. The last line is generating an error:

RuntimeError: Object: Error in executing tool)

I can't identify what I'm doing wrong. All is in WGS84. Here's the code

import arcpy
from arcgis.gis import GIS

gis = GIS("https://www.arcgis.com", "XXXX", "XXXX")
append_layer_itemid = '33518827e9e24defbacd671bfd26XXXX'

#Grab the layer
fs_item = gis.content.get(append_layer_itemid)
fs_layer = fs_item.layers[0]

#make a layer with the points
arcpy.env.workspace = r"C:\Users\cbent\OneDrive\Documents\ArcGIS\Projects\MyProject\MyProject.gdb"
arcpy.MakeFeatureLayer_management('points_layer', 'point_layer')

arcpy.SelectLayerByLocation_management(fs_layer,'INTERSECT','point_layer')

 

It's the last line that's failing, any ideas?

Chuck

 

 

0 Kudos
1 Solution

Accepted Solutions
ChuckBenton
Occasional Contributor

Changing fs_layer in arcpy.SelectLayerByLocation_management(fs_layer,'INTERSECT','point_layer') to "https://services8.arcgis.com/2G8bTpCps4vdRut5/arcgis/rest/services/ParcelAtlas_V2_4/FeatureServer/0" fixed the issue. Basically had to use the service URL directly.

View solution in original post

3 Replies
DanPatterson
MVP Esteemed Contributor

it may be failing here

arcpy.MakeFeatureLayer_management('points_layer', 'point_layer')

You might want to use arcpy.Exists  to confirm the existence prior to select by location.  It would also be a good idea to check both layer coordinate systems while you are at it and bail if they differ


... sort of retired...
0 Kudos
ChuckBenton
Occasional Contributor

 The online Parcel Layer is in WGS_1984_Web_Mercator_Auxiliary_Sphere (WKID 3857). Earlier I did have the point layer in a different WGS 1984 WKID, which has been corrected.

I now print the point_layer WIKI and bail if it isn't 3857. I also confirm it exists. Still seeing the same error:

RuntimeError: Object: Error in executing tool

. Any suggestions?

0 Kudos
ChuckBenton
Occasional Contributor

Changing fs_layer in arcpy.SelectLayerByLocation_management(fs_layer,'INTERSECT','point_layer') to "https://services8.arcgis.com/2G8bTpCps4vdRut5/arcgis/rest/services/ParcelAtlas_V2_4/FeatureServer/0" fixed the issue. Basically had to use the service URL directly.