What is a good way to skip a blank field when creating label expressions? I have a bunch of points that I need labeled with data from multiple fields but some contain blanks. I am working in ArcPro if that makes any difference.
what labelling method are you using? standard or maplex? What types of the fields are involved? labelling language?
Perhaps some examples from your case.
In essence, you can create a labelling function that will use the inputs from fields and translate any nulls to an empty string prior to concatenation
http://pro.arcgis.com/en/pro-app/help/mapping/text/specify-text-for-labels.htm
Can you share an example of a label including blank fields and what you want to have as a result? There are multiple ways to achieve this and an example will make it easier to suggest a good way to do this.
I am using Maplex. The fields are text fields.
The Popup2 field has blanks in that I want to omit when I generate the labels. The red arrows are the blanks I am trying to remove.
Right now I am using a basic expression to create them.
[Name2] + '\n' + [PopUp2] + '\n' + [DMSLat] + '\n' + [DMSLong]
Thanks for taking the time to help.
A demo... a, b, c, d represent field names
they need to be replace with !YourFieldName! in ! marks
Python parser
could be used in a field calculation and I presume in some labeling thing (don't do much mapping with labels, so I will defer to those that do)
a<SPAN class="punctuation token">,</SPAN> b<SPAN class="punctuation token">,</SPAN> c<SPAN class="punctuation token">,</SPAN> d <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'a'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">''</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'c'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'d'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">prn</SPAN><SPAN class="punctuation token">(</SPAN>a<SPAN class="punctuation token">,</SPAN> b<SPAN class="punctuation token">,</SPAN> c<SPAN class="punctuation token">,</SPAN> d<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"""demo replace the letters with !YourFieldName! """</SPAN> <SPAN class="keyword token">if</SPAN> b <SPAN class="operator token">not</SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">" "</SPAN><SPAN class="punctuation token">,</SPAN> None<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> frmt <SPAN class="operator token">=</SPAN> <SPAN class="string token">"{}\n{}\n{}\n{}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>a<SPAN class="punctuation token">,</SPAN> b<SPAN class="punctuation token">,</SPAN> c<SPAN class="punctuation token">,</SPAN> d<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> frmt <SPAN class="operator token">=</SPAN> <SPAN class="string token">"{}\n{}\n{}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>a<SPAN class="punctuation token">,</SPAN> c<SPAN class="punctuation token">,</SPAN> d<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN> frmt prn<SPAN class="punctuation token">(</SPAN>a<SPAN class="punctuation token">,</SPAN> b<SPAN class="punctuation token">,</SPAN> c<SPAN class="punctuation token">,</SPAN> d<SPAN class="punctuation token">)</SPAN> <SPAN class="string token">'a\nc\nd'</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>prn<SPAN class="punctuation token">(</SPAN>a<SPAN class="punctuation token">,</SPAN> b<SPAN class="punctuation token">,</SPAN> c<SPAN class="punctuation token">,</SPAN> d<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> a c d<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
forgot this missive....
*args would require some field names of indeterminate length
ie prn(!A!, !b!, !cc!, !d!) as the expression
a<SPAN class="punctuation token">,</SPAN> b<SPAN class="punctuation token">,</SPAN> c<SPAN class="punctuation token">,</SPAN> d <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'a'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">''</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'c'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'d'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">prn</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="operator token">*</SPAN>args<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"""demo replace the letters with !YourFieldName! """</SPAN> vals <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>i <SPAN class="keyword token">for</SPAN> i <SPAN class="keyword token">in</SPAN> args <SPAN class="keyword token">if</SPAN> i <SPAN class="operator token">not</SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">" "</SPAN><SPAN class="punctuation token">,</SPAN> None<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN> frmt <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"{}\n"</SPAN><SPAN class="operator token">*</SPAN>len<SPAN class="punctuation token">(</SPAN>vals<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN><SPAN class="operator token">*</SPAN>vals<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN> frmt <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>prn<SPAN class="punctuation token">(</SPAN>a<SPAN class="punctuation token">,</SPAN> b<SPAN class="punctuation token">,</SPAN> c<SPAN class="punctuation token">,</SPAN> d<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># in the order given</SPAN> a c d <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>prn<SPAN class="punctuation token">(</SPAN>a<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># a singleton</SPAN> a <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>prn<SPAN class="punctuation token">(</SPAN>a<SPAN class="punctuation token">,</SPAN> d<SPAN class="punctuation token">,</SPAN> c<SPAN class="punctuation token">,</SPAN> b<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># switch them up</SPAN> a d c <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
But if you want to change the separator, you can use this variant
<SPAN class="comment token"># --- requires python 3.6 or above</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">prn</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="operator token">*</SPAN>args<SPAN class="punctuation token">,</SPAN> sep<SPAN class="operator token">=</SPAN><SPAN class="string token">"..."</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"""demo replace the letters with !YourFieldName! """</SPAN> vals <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>f<SPAN class="string token">"{i}"</SPAN><SPAN class="operator token">+</SPAN>sep <SPAN class="keyword token">for</SPAN> i <SPAN class="keyword token">in</SPAN> args <SPAN class="keyword token">if</SPAN> i <SPAN class="operator token">not</SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">" "</SPAN><SPAN class="punctuation token">,</SPAN> None<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN> frmt <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"{}"</SPAN><SPAN class="operator token">*</SPAN>len<SPAN class="punctuation token">(</SPAN>vals<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN><SPAN class="operator token">*</SPAN>vals<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN> frmt prn<SPAN class="punctuation token">(</SPAN>a<SPAN class="punctuation token">,</SPAN> c<SPAN class="punctuation token">,</SPAN> d<SPAN class="punctuation token">)</SPAN> <SPAN class="string token">'a...c...d...'</SPAN> <SPAN class="comment token"># ---- change sep="\n" for newline instead</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
... and since you can use Arcade too for the labeling, find an example below:
<SPAN class="keyword token">var</SPAN> Name2 <SPAN class="operator token">=</SPAN> <SPAN class="string token">"FR-20"</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> PopUp2 <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> DMSLat <SPAN class="operator token">=</SPAN> <SPAN class="string token">"37°32'5.460\"N"</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> DMSLong <SPAN class="operator token">=</SPAN> <SPAN class="string token">"113°4'53.641\"W"</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// var Name2 = $feature.Name2;</SPAN> <SPAN class="comment token">// var PopUp2 = $feature.PopUp2;</SPAN> <SPAN class="comment token">// var DMSLat = $feature.DMSLat;</SPAN> <SPAN class="comment token">// var DMSLong = $feature.DMSLong;</SPAN> <SPAN class="keyword token">var</SPAN> array <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>Name2<SPAN class="punctuation token">,</SPAN> PopUp2<SPAN class="punctuation token">,</SPAN> DMSLat<SPAN class="punctuation token">,</SPAN> DMSLong<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> result <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">for</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">var</SPAN> i <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">;</SPAN> i <SPAN class="operator token"><</SPAN> <SPAN class="token function">Count</SPAN><SPAN class="punctuation token">(</SPAN>array<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> i<SPAN class="operator token">++</SPAN> <SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="token function">IsEmpty</SPAN><SPAN class="punctuation token">(</SPAN>array<SPAN class="punctuation token">[</SPAN>i<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>result <SPAN class="operator token">==</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> result <SPAN class="operator token">=</SPAN> array<SPAN class="punctuation token">[</SPAN>i<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">else</SPAN> <SPAN class="punctuation token">{</SPAN> result <SPAN class="operator token">=</SPAN> result <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\n"</SPAN> <SPAN class="operator token">+</SPAN> array<SPAN class="punctuation token">[</SPAN>i<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">return</SPAN> result<SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
On lines 1 to 4 I'm setting some values hard coded. Lines 6 to 9 show how these values can be read from the fields.
This will yield the label without the empty line:
I will try this one. I have been wanting to learn Arcade a little more.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.