Select to view content in your preferred language

Why isn't this label code working?

665
2
01-18-2019 11:52 AM
EricEagle
Frequent Contributor

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?

Tags (1)
0 Kudos
2 Replies
MarkBockenhauer
Esri Regular Contributor

Eric,

I was curious about this one and using ArcGIS Pro 2.3  I see the following:

seems to work?

2.3 will be available soon.

Mark

EricEagle
Frequent Contributor

Mark, thanks for the reply - I went and typed it back in from scratch, and it worked - what can I say, regex is tricky sometimes, though my face is a bit red for submitting a question that ultimately was due to my own typo!!

0 Kudos