Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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