Checking if a layer is hosted, part 2

250
1
07-07-2022 11:50 AM
AlfredBaldenweck
MVP Regular Contributor

Hi all,

Kind of a follow-up to this post.

I was looking over some documentation and noticed that in arcpy.mp, layers have an IsWebLayer method.

I'm wondering what exactly it's checking to figure that out. Reading the .py file, it just says passthrough_attr('isWebLayer'), and looking up passthrough_attr() doesn't really tell me anything useful.

What is the functional difference between using .isWebLayer() and, for example, arcpy.Describe() to check for "https://" in the catalogPath? 

I'm also curious as whether there is any benefit to using one versus the other? Obviously, isWebLayer requires far less typing, but I'm wondering if there are any other pros or cons to either of them. 

Thanks!

I tried checking myself, but both return the same results:

aprx = arcpy.mp.ArcGISProject("CURRENT")
mapList= aprx.listMaps("Map")[0]
layList = mapList.listLayers()

def recList(layList):
    for lay in layList:
        if lay.isGroupLayer is True:
            recList(lay.listLayers())
        else:
            if lay.isWebLayer is True:
                print(f"{lay} is a web layer")

            dSource= lay.dataSource
            cPath=(arcpy.Describe(dSource).catalogPath)
            if "https://" in cPath:
                print(f"{lay} contains 'https://'")
recList(layList)

 

AlfredBaldenweck_0-1657218954725.png

 

 

 

0 Kudos
1 Reply
SamSzotkowski
New Contributor III

I cannot comment on the functional difference.  But as for pros and cons, from a practical standpoint I would lean towards isWebLayer being better, because ESRI devs probably have a lot more info about what does and doesn't behave as a web layer, whereas you're only checking for one particular case (probably like 99% coverage, but still just one case).  You don't (unless someone chimes in here) have enough info to know if there are edge cases, let alone how to handle them.

If it's a feature class instead of a layer, you don't have much of a choice, but if you're reading a layer might as well take the easy option.

More broadly, you should use isWebLayer because it's much clearer to anyone else (including your future self) reading your code as to what that means.  I haven't tested it, but I'd bet good money that grabbing that one property is faster than grabbing the data source, calling describe, grabbing another property, and doing an "if".  Less is more.

0 Kudos