4

I am using Python to update layer names and symbology on a map layout. Some layer names may be different so I was attempting to use a wildcard, but am not having luck. I am not receiving an error, but nothing is changing. The layer name could be named FirePoint_1, FirePoint_2, ... etc.

for lyr in mp.listLayers():

    if lyr.isFeatureLayer:
        sym = lyr.symbology
        
        if lyr.name == "FirePoint*":
                lyr.name = "Fire Origin"
                sym.renderer.symbol.applySymbolFromGallery("Fire Station")
                lyr.symbology = sym
4
  • 5
    Try: if lyr.name.startswith('FirePoint'):
    – Ben W
    Dec 1 '21 at 5:24
  • Thank you kindly - that works perfectly.
    – kart
    Dec 1 '21 at 5:35
  • 3
    Pure Python questions are better researched in Stack Overflow
    – Vince
    Dec 1 '21 at 6:11
  • 3
    Or if 'FirePoint' in lyr.name:
    – BERA
    Dec 1 '21 at 6:12
4

You can use Python's re module for wildcards.

Here is how you can do it with re.match()

import re

for lyr in mp.listLayers():

    if lyr.isFeatureLayer:
        sym = lyr.symbology

        if re.match("FirePoint.+", lyr.name):
            lyr.name = "Fire Origin"
            sym.renderer.symbol.applySymbolFromGallery("Fire Station")
            lyr.symbology = sym

Not the answer you're looking for? Browse other questions tagged or ask your own question.