Select to view content in your preferred language

Cannot access the feature layer from a web map using ArcGIS API Python

264
0
02-07-2022 09:51 AM
Aravinthkumar
New Contributor III

Hello everyone, 

 

I am trying to get the specific feature layer from the web map from the Portal based on its unique values, but nothing is printed in the results, but there are the feature layers present in lot of the web maps, the print function before the function def find_maps_with_layer works and prints the web_map_items, but inside the class nothing is working, I cannot figure out the mistake. What am I doing wrong ? Inside the function nothing is working. Any insights will be helpful. Thank you..

 

from arcgis import GIS



portalUrlP = https://maps-url/portal/
userP = "user"
passwordP = "pass"

gisP = GIS(url=portalUrlP, username=userP, password=passwordP, verify_cert=False)


**#web_map_items = gisP.content.search(query="", item_type="Web Map", max_items=10000)**
**#print(web_map_items)**


def find_maps_with_layer(lyr_to_find=None):

    from arcgis.mapping import WebMap


    sitGis = {"lonie":1, "bulbj":1}
    print(sitGis)
    web_map_items = gisP.content.search(query="", item_type="Web Map", max_items=10000)
    print(web_map_items)
    print(f"Searching {len(web_map_items)} web maps")
    maps_with_layer = []
    for item in web_map_items:
        if item.owner in sitGis:
            wm = WebMap(item)
            lyrs = wm.layers
            for lyr in lyrs:
                if hasattr(lyr, "url"):
                    if lyr_to_find == lyr.url:

                        if "layerDefinition" in lyr:
                            layerDefinition = lyr["layerDefinition"]
                            if "drawingInfo" in layerDefinition:
                                drawingInfo = layerDefinition["drawingInfo"]
                                if "renderer" in drawingInfo:

                                    renderer = drawingInfo["renderer"]
                                    if "uniqueValueInfos" in renderer:

                                        uniqueValueInfos = renderer["uniqueValueInfos"]
                                        print(f'{item.title} contains the layer, {uniqueValueInfos}')

                                        with open("maps_with_service_WETTBEWERBER_VERSCHIEBE_INT_UNIQEVALUS", "a") as file:
                                            file.write(f"{item.title}, {item.id}, {item.owner} \n")
                                            file.write(f"\n")

                                        maps_with_layer.append(item)

    print(f"Found {len(maps_with_layer)} maps which contain the layer")
    return maps_with_layer


# Parameters:
lyr_to_find = "https://maps-url.com/server/rest/services/WETTBEWERBER_V2/FeatureServer/0"
Tags (1)
0 Kudos
0 Replies