AnsweredAssumed Answered

Why isn't this label code working?

Question asked by eric.eagle on Jan 18, 2019
Latest reply on Jan 23, 2019 by eric.eagle

I've got a bunch of OpenStreetMap content that I'm trying to label (ArcGIS Pro 2.2.4) based on whether content is found in the other_tags field.  Here's what I'm trying to do in the expression editor (Python):

 

def FindLabel ( [other_tags] ):
    import re
    ls = [other_tags]
    slabel = re.search('"name:en"=>"(.*?)","', ls)
    return slabel.group(1)

 

It says "NameError: name 'FindLabel' is not defined

 

Which is weird because if I remove the "," from the regex operation and do this:

 

def FindLabel ( [other_tags] ):
    import re
    ls = [other_tags]
    slabel = re.search('"name:en"=>"(.*?)"', ls)
    return slabel.group(1)

it renders as valid, although it prints out everything beyond the "name:en"=>" string.

 

I have also tried this, which validates but returns nothing:

 

def FindLabel ( [other_tags] ):
    ss = [other_tags]
    ls = ss[ss.find('"name:en"=>"')+1:ss.find('"')]
    return ls

 

Here is a bit of the sort of substring someone could expect to find in OSM's other_tags:

 

"int_name"=>"Dubai","is_in:continent"=>"Asia","is_in:country_code"=>"AE","name:en"=>"Dubai","population"=>"1984000"....

 

Can anyone help me to get this label expression working?

Outcomes