Select to view content in your preferred language

How to modify Line Thickness by Category using Map Class methods

2781
2
Jump to solution
09-21-2022 12:47 AM
Labels (2)
Anthony_R_McKay
Regular Contributor

I am doing a Python project on Stream Order.

So far my script can generate a stream vector fc  (called 'Stream') and copy this into a map (called 'Map')

Capture.JPG

The script then colours the polylines blue according to a classification in the field 'grin_code' (actually the Strahler classification number, 1 to 4).

"# specify map in project named "Map"
m = p.listMaps('Map')[0]

# specify lyaer in map named "stream"
lyr = m.listLayers('Stream')[0]

# access symbology of maps and change symbology to graduated colors
sym = lyr.symbology
sym.updateRenderer('UniqueValueRenderer')
sym.renderer.fields = ['grid_code']


colorRamp = p.listColorRamps("Blues")[0]
sym.renderer.colorRamp = colorRamp
# sym.renderer.colorRamp = "Blues(4 Classes)_Sequential_2"

# save symbology back onto maps
lyr.symbology = sym

# save project
p.save()"

Capture1.JPG

Now, I would like to adjust the line thickness for each category  according to 'grid_code'.

This is what I did in ArcGIS Pro to achieve what I wanted.

Capture2.JPG

What I would like to know is , how do I go about this in Python?

Creating these flow analyses is a fairly common task - so it is possible that creating this visualisation this has been tackled before.

Any help very much appreciated.

 

 

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Alum
for width, item in enumerate(sym.renderer.groups[0].items):
    item.symbol.size = width
lyr.symbology = sym

Have a great day!
Johannes

View solution in original post

0 Kudos
2 Replies
JohannesLindner
MVP Alum
for width, item in enumerate(sym.renderer.groups[0].items):
    item.symbol.size = width
lyr.symbology = sym

Have a great day!
Johannes
0 Kudos
Anthony_R_McKay
Regular Contributor

Well done Johannes,

So simple and easy to add to my code.

I only made one small change "width+1" as the zero indexing caused the '1' class to be zero width.

Such an elegant solution,

Thanks so much,

Anthony

for width, item in enumerate(sym.renderer.groups[0].items):
    item.symbol.size = width+1
lyr.symbology = sym

 

 

0 Kudos