Is there a way to add checkboxes to the layer symbology in the Table of Contents — to toggle symbology classes on and off?
Maybe the underlying mechanism would be an automatically-generated display filter?
SQL Expression:
AND (<symbology class value field> IN (45,46,47,48))
Is that kind of thing possible? Is the Pro SDK the right mechanism?
No idea about the SDK, but you can convert the layer to multiple query layers:
def convert_unique_symbol_layer_to_query_layers(layer_name):
# get the symbology fields and items
layer = arcpy.mp.ArcGISProject("current").activeMap.listLayers(layer_name)[0]
renderer = layer.symbology.renderer
fields = renderer.fields
items = renderer.groups[0].items
# loop over the items
for item in reversed(items):
# create the query layer
values = item.values[0]
query = " AND ".join([f"{fields[i]} = '{values[i]}'" for i in range(len(fields))])
print(f"Creating query layer {item.label} with query {query}")
query_layer = arcpy.management.MakeFeatureLayer(layer, item.label, query)[0]
# change the symbology
symbology = query_layer.symbology
symbology.updateRenderer("SimpleRenderer")
symbology.renderer.symbol = item.symbol
query_layer.symbology = symbology
convert_unique_symbol_layer_to_query_layers("Bauwerke")
I haven't found a way to apply symbol rotation with arcpy, so that's a smallish problem for point layers (eg the "Brücke" layer).
@JohannesLindner That’s useful.
Out of curiosity, what was you reasoning for using query layers (enterprise GDBs-only) vs. generic TOC feature layers (datatype-agnostic)?
Oh, that's just unfortunate naming of the variable.
Despite me calling the variable query_layer, I'm not using Make Query Layer (which, correct, can only be used with an Enterprise gdb).
Instead, I'm using Make Feature Layer, which takes an optional where clause and can be used with all feature sources (fgdb, egdb, feature service, shape file, ...). It basically creates a new layer and sets its definition query.