select by location using "layer URL" instead of layer name

06-06-2020 12:36 PM
New Contributor III

Hy guys, is there any way to use the select by location tool (via python) but using layer URL not layer name
eg: arcpy.SelectLayerByLocation_management(URL layer1"CROSSED_BY_THE_OUTLINE_OF",URL layer2,"","ADD_TO_SELECTION")
also I want to use searchCursor and updateCursor using Layer URL not layer name
I mean by URL, the REST URL of my layer service on arcgis online
I am using ArcGis Pro
Thank you

5 Replies
MVP Esteemed Contributor

With arcpy in arcgis pro

Select Layer By Location—Data Management toolbox | Documentation 

using the api for python

arcgis.features module — arcgis 1.8.0 documentation 

no mention of url's though

... sort of retired...
0 Kudos
MVP Esteemed Contributor

Take a look at an earlier post of mine : Using arcpy to copy a portal feature service to a fgdb feature class 

In it, Joshua Bixby‌ provides me with a solution that I got to work to downloade a feature in a hosted feature layer to a local file gdb.  He may be able to provide a bit more insight to your specific quest.  I too have a need to use arcpy functions like arcpy.ListFields() on a hosted feature service; it would be nice to use cursors as well.

Dan Patterson‌ : if it ain't one new thing it's another: arcade one day, python api the next...

That should just about do it....
0 Kudos
MVP Esteemed Contributor

This can all be done using ArcPy.  Just use Make Feature Layer—Data Management toolbox | Documentation to make a layer first and then run your selection against it.  If you are running a standalone script outside of ArcGIS Pro, use SignInToPortal—ArcPy Functions | Documentation to authenticate your Python session first.

MVP Esteemed Contributor

This morning I was able to use arcpy commands easily by simply referring to a feature layer's url:

import arcpy

fc = r''

for f in arcpy.ListFields(fc):

with arcpy.da.SearchCursor(fc,'*') as cursor:
    for row in cursor:

# both work as expected from a spyder console...       
That should just about do it....
Occasional Contributor

Did you ever resolve this?  I'm having a similar issue, and the online layer is massive (167M+ records) so copying isn't practical. See for details.

0 Kudos