3

I'm trying to remove WMS layers from an mxd using arcpy. I can successfully remove "MapServer" type services using the below code, but not WMS?

Here is an example mxd (zipped) with two different WMS layers that I'm trying to remove: here

Also, I've posted on the ArcGIS Resources forum too: here

Code:

import arcpy, os

inFName = "wms.mxd"
outFName = "wms_removed.mxd"
pth = r"c:\temp"
inFULLPTH = os.path.join(pth,inFName)
outFULLPTH = os.path.join(pth,outFName)
mxd = arcpy.mapping.MapDocument(inFULLPTH)

for df in arcpy.mapping.ListDataFrames(mxd):
    LyrList = arcpy.mapping.ListLayers(mxd, "", df)

    for lyr in LyrList:
        if lyr.supports("SERVICEPROPERTIES"):
            if lyr.serviceProperties["ServiceType"] == "WMS":
                arcpy.mapping.RemoveLayer(df, lyr)

mxd.saveACopy(outFULLPTH)
del mxd

Any ideas? Is arcpy.mapping.RemoveLayer the best approach ? I have hundreds of mxds to crawl through and want to remove WMS layers from them.

1 Answer 1

3

I've looked at your MXD and it seems the problem might be with the WMS layers being sub-layers of the main WMS layer. I don't think it's possible to remove these 'sub-layers' with python as it's not possible to do in the GUI of ArcMap. Does this make sense? I could be wrong, but this is what my intuition is telling me. You might want to try removing the parent WMS layer all together.

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.