Select to view content in your preferred language

how to use displayfilter in arcpy

645
3
09-17-2023 07:23 AM
cheffing
New Contributor

Hi, I am looking for examples how to use displayfilters in arcpy. Found only answers about definitionqueries...
Thanks for your help, Christoph

0 Kudos
3 Replies
anbinh
by
Frequent Contributor

Doesn't seem like there is a direct way to control Display Filter from arcpy. 

However, you may find this post helpful Solved: Controlling Pro Display Filters with arcpy - Esri Community

 

Ta,

AB

0 Kudos
cheffing
New Contributor

Hi AB, thanks, but I saw this already. I need the full layer defined and only want to filter the visibility of certan features. With the definitionquery it would be possible with serveral workarounds ... displayfilter would be very usefull to manage by arcpy.
Best Regards, Christoph

0 Kudos
JohannesLindner
MVP Frequent Contributor

You can get and set them via the CIM.

# get the layer
aprx = arcpy.mp.ArcGISProject("current")
layer = aprx.activeMap.listLayers("LayerName")[0]

# get the layer's cim
cim = layer.getDefinition("V3")

# create a new display filter
new_filter = arcpy.cim.CIMVectorLayers.CIMDisplayFilter()
new_filter.whereClause = "Your query here"

# set the CIM's displayFilters attribute and apply the CIM to the layer
cim.displayFilters = [new_filter]
layer.setDefinition(cim)



# to remove all filters:
cim.displayFilters = []
layer.setDefinition(cim)

 

Prepare a layer with display queries and get it's CIM to play around with the relevant attributes:

  • displayFilterChoices
  • displayFilterName
  • displayFilters
  • displayFiltersType
  •  

Have a great day!
Johannes
0 Kudos