How to remove a specific unique value with arcpy

المشرف العام

Administrator
طاقم الإدارة
using arcpy, i would like to remove,from 50 mxd files, a specific unique value called "residence a" (exist in 3 layers) from the table of content.



so i will get this result:



The value of "residence a" is "70" in the attribute table (in field named "YEUD")



When i use this code:

import arcpy,os,sysfrom arcpy import envenv.workspace = r"C:\Project"for mxdname in arcpy.ListFiles("*.mxd"): mxd = arcpy.mapping.MapDocument(r"C:\Project\\" + mxdname) df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] lyr = arcpy.mapping.ListLayers(mxd, "*")[0] if lyr.symbologyType == "UNIQUE_VALUES": vals = lyr.symbology.classLabels for v in vals: if v == "residence a": print mxdname print lyr.name print ("1 in layer " + lyr.name) arcpy.mapping.RemoveLayer(df, v) mxd.save()del mxdi get en error:

>>> Project -.mxdmig11 in layer mig1Traceback (most recent call last): File "C:/Users/yaron.KAYAMOT/Desktop/remove UNIQUE_VALUES in lyr.py", line 18, in arcpy.mapping.RemoveLayer(df, v) 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)AssertionError>>> For disclosure, i asked this question in https://geonet.esri.com/thread/158715



أكثر...
 
أعلى