Select to view content in your preferred language

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

2188
5
06-06-2020 12:36 PM
MedMZOURI
Occasional Contributor

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
DanPatterson
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
JoeBorgione
MVP Emeritus

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
JoshuaBixby
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.

JoeBorgione
MVP Emeritus

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

import arcpy

fc = r'https://www.my.org/gisfed/rest/services/###/FeatureServer/9'

for f in arcpy.ListFields(fc):
    print(f.name)

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

# both work as expected from a spyder console...       
That should just about do it....
ChuckBenton
Frequent 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 https://community.esri.com/t5/arcgis-api-for-python-questions/select-by-location-from-online-feature... for details.

0 Kudos