1

I am trying to get the list of feature service which has a specific layer (for example: River (the layer id is 0)) from a feature service,

from arcgis.gis import GIS
gis = GIS(url='https://pythonapi.playground.esri.com/portal', username='arcgis_python', password='amazing_arcgis_123')

search_result = gis.content.search(query="River", item_type="Feature Layer")
for layer in search_result:
    if "River" in layer.title.lower():
        print(f"Layer name: {layer.title}, \tOwner: {layer.owner}, \tLayer ID: {layer.id}")

But no results are printed out, but the layer River is present in most of my feature service. What can be done in this case ??

9
  • When you say the layer "River" is present in most of my feature service, do you mean services tied to YOUR account? Because your code is using the sample Python API credentials which appear to authenticate against a specific Portal (NOT ArcGIS Online). The search is sandboxed to a very limited set of content, not all of arcgis.
    – KHibma
    Jan 26, 2022 at 15:36
  • @KHibma, I have just given the url and credentials for example, I am an admin in the portal and using those credentials. Yes the services are tied to my account.
    – Aravinth
    Jan 26, 2022 at 15:40
  • Ok, If you remove the if "River" in layer.title part of the code and just print the output of the loop, can you confirm your code finds anything at all?
    – KHibma
    Jan 26, 2022 at 15:42
  • Actually, the most likely problem is this: layer.title.lower() --- "River" (capital R) will NEVER be found in river more river, this is my lowercase river
    – KHibma
    Jan 26, 2022 at 15:44
  • @KHibma, yes I have tried that too, nothing is printed out. But If I open the feature service it contains 5 layers including River in it.
    – Aravinth
    Jan 26, 2022 at 15:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.