Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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)

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

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

Your Answer


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.