Select to view content in your preferred language

ArcPy - retrieve scale-based symbol class min/max scales

695
2
Jump to solution
04-28-2023 08:03 AM
DavidPike
MVP Frequent Contributor

Hi,

ArcGIS Pro 2.8.1, Python either in notebook or IDLE.

I'm trying to create simple tool to list layer properties of any given aprx/mapx.  I'm happy enough with retrieving the basic layer properties needed, however I can't seem to find a way of accessing unique symbol scale settings. https://pro.arcgis.com/en/pro-app/latest/help/mapping/layer-properties/scale-based-symbol-classes.ht...

I've had a look at the unique value renderer Class but can't see anything jumping out at me.  Also thinking of complications where scale-based symbology is set up..

Any ideas much appreciated.

 

 

#simple script to get layer scale
import arcpy
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps()[0]
for lyr in m.listLayers():
    if lyr.supports("dataSource"):
        print(lyr.name, lyr.minThreshold, lyr.maxThreshold)

 

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

You have to dive into the CIM for that.

def get_min_max_scale(layer):
    result = dict()
    cim = layer.getDefinition('V3')
    renderer = cim.renderer
    try:
        symbol_classes = renderer.groups[0].classes
    except (AttributeError, IndexError):
        print("Symbology not applicable!")
        symbol_classes = []
    for sc in symbol_classes:
        result[sc.label] = [sc.symbol.minScale, sc.symbol.maxScale]
    return result


lyr_with_unique_symbols = arcpy.mp.ArcGISProject("current").activeMap.listLayers("TestPoints")[0]
get_min_max_scale(lyr_with_unique_symbols)
#{'capital': [0.0, 0.0], 'city': [500000, 0.0], 'town': [100000, 0.0], 'village': [50000, 0.0]}

lyr_with_single_symbol = arcpy.mp.ArcGISProject("current").activeMap.listLayers("TestLines")[0]
get_min_max_scale(lyr_with_single_symbol)
#Symbology not applicable!
#{}

Have a great day!
Johannes

View solution in original post

0 Kudos
2 Replies
JohannesLindner
MVP Frequent Contributor

You have to dive into the CIM for that.

def get_min_max_scale(layer):
    result = dict()
    cim = layer.getDefinition('V3')
    renderer = cim.renderer
    try:
        symbol_classes = renderer.groups[0].classes
    except (AttributeError, IndexError):
        print("Symbology not applicable!")
        symbol_classes = []
    for sc in symbol_classes:
        result[sc.label] = [sc.symbol.minScale, sc.symbol.maxScale]
    return result


lyr_with_unique_symbols = arcpy.mp.ArcGISProject("current").activeMap.listLayers("TestPoints")[0]
get_min_max_scale(lyr_with_unique_symbols)
#{'capital': [0.0, 0.0], 'city': [500000, 0.0], 'town': [100000, 0.0], 'village': [50000, 0.0]}

lyr_with_single_symbol = arcpy.mp.ArcGISProject("current").activeMap.listLayers("TestLines")[0]
get_min_max_scale(lyr_with_single_symbol)
#Symbology not applicable!
#{}

Have a great day!
Johannes
0 Kudos
DavidPike
MVP Frequent Contributor

Absolute genius, thanks Johannes!

0 Kudos