Select to view content in your preferred language

Customize Pro UI: Checkboxes in TOC to toggle symbol classes

708
3
12-08-2022 06:00 AM
Bud
by
Esteemed Contributor

Is there a way to add checkboxes to the layer symbology in the Table of Contents  — to toggle symbology classes on and off?

Bud_0-1670507450501.png

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?

 

0 Kudos
3 Replies
JohannesLindner
MVP Frequent Contributor

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")

 

JohannesLindner_0-1670582773260.png

JohannesLindner_1-1670582845335.png

 

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).


Have a great day!
Johannes
Bud
by
Esteemed Contributor

@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)?

0 Kudos
JohannesLindner
MVP Frequent Contributor

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.


Have a great day!
Johannes