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):
<SPAN class="keyword token">def</SPAN> FindLabel <SPAN class="punctuation token">(</SPAN> <SPAN class="punctuation token">[</SPAN>other_tags<SPAN class="punctuation token">]</SPAN> <SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">import</SPAN> re
ls <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>other_tags<SPAN class="punctuation token">]</SPAN>
slabel <SPAN class="operator token">=</SPAN> re<SPAN class="punctuation token">.</SPAN>search<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'"name:en"=>"(.*?)","'</SPAN><SPAN class="punctuation token">,</SPAN> ls<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">return</SPAN> slabel<SPAN class="punctuation token">.</SPAN>group<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
It says "NameError: name 'FindLabel' is not defined
Which is weird because if I remove the "," from the regex operation and do this:
<SPAN class="keyword token">def</SPAN> FindLabel <SPAN class="punctuation token">(</SPAN> <SPAN class="punctuation token">[</SPAN>other_tags<SPAN class="punctuation token">]</SPAN> <SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">import</SPAN> re
ls <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>other_tags<SPAN class="punctuation token">]</SPAN>
slabel <SPAN class="operator token">=</SPAN> re<SPAN class="punctuation token">.</SPAN>search<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'"name:en"=>"(.*?)"'</SPAN><SPAN class="punctuation token">,</SPAN> ls<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">return</SPAN> slabel<SPAN class="punctuation token">.</SPAN>group<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
it renders as valid, although it prints out everything beyond the "name:en"=>" string.
I have also tried this, which validates but returns nothing:
<SPAN class="keyword token">def</SPAN> FindLabel <SPAN class="punctuation token">(</SPAN> <SPAN class="punctuation token">[</SPAN>other_tags<SPAN class="punctuation token">]</SPAN> <SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
ss <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>other_tags<SPAN class="punctuation token">]</SPAN>
ls <SPAN class="operator token">=</SPAN> ss<SPAN class="punctuation token">[</SPAN>ss<SPAN class="punctuation token">.</SPAN>find<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'"name:en"=>"'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="operator token">+</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN>ss<SPAN class="punctuation token">.</SPAN>find<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'"'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">return</SPAN> ls<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
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"....<SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
Can anyone help me to get this label expression working?