In case you've been following my fairly boring saga: I am making progress on my program! I have my files going where they need to go! Yay!
I am trying to remove intermediate and unnecessary layers from the map document. I have a raster file, "SoilUnclass", that I want to remove from my map document to de-clutter my Table of Contents. I put the following code together based on what I've seen and read. I left my variable definitions out of the code but my inputs are all initialized with the proper file paths.
SoilUnclass = arcpy.PolygonToRaster_conversion(soil, "HSG", ScratchPath + r"\SoilUnclass", "MAXIMUM_COMBINED_AREA") SoilClass = arcpy.sa.Reclassify(SoilUnclass, "HSG", arcpy.sa.RemapValue([["A", 1], ["B", 2], ["C", 3], ["D", 4], ["A/D", 14], ["B/D", 24], ["C/D", 34], ["---", 4]]), "NODATA") SoilClass.save(WorkPath + r"\SoilClass") SoilClass.save(GDBpath + r"\SoilClass") df = arcpy.mapping.ListDataFrames(mxd,"*") arcpy.mapping.RemoveLayer(df, SoilUnclass)
When I run that code, I receive the following error:
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\utils.py", line 182, in fn_
return fn(*args, **kw)
File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\mapping.py", line 1845, in RemoveLayer
assert isinstance(remove_layer, Layer)
...?? It may be worth noting that when I do arcpy.mapping.ListLayers(mxd), "SoilUnclass" is not a layer that shows up. Only the files that were in the map document before I ran my code are listed. I saved my document and did ListLayers() again but nothing changed. How can I get access to these layers to modify them?