Writing label expression with ArcMap and If then Statement?












2














I am having problems with label expression in ArcMap 10.2.1.



I want to show two labels per polygon, but only when there are two labels to show.
Every polygon has at least one label (Veg_Dominant), but some polygons also have a second (Veg_codominant). I want polygons with only one label to show this one label, and polygons with two labels to show both with a '+' sign in between.



This is how I entered it in the label expression:



enter image description here



This is how it looks in the map:



enter image description here



is there a way to only show the '+' sign when there is more than one label to show?










share|improve this question
























  • Click on Help in the lower middle of your label expression dialog. The If-Else statement is one of the examples there.
    – Matte
    Nov 20 at 10:58
















2














I am having problems with label expression in ArcMap 10.2.1.



I want to show two labels per polygon, but only when there are two labels to show.
Every polygon has at least one label (Veg_Dominant), but some polygons also have a second (Veg_codominant). I want polygons with only one label to show this one label, and polygons with two labels to show both with a '+' sign in between.



This is how I entered it in the label expression:



enter image description here



This is how it looks in the map:



enter image description here



is there a way to only show the '+' sign when there is more than one label to show?










share|improve this question
























  • Click on Help in the lower middle of your label expression dialog. The If-Else statement is one of the examples there.
    – Matte
    Nov 20 at 10:58














2












2








2


1





I am having problems with label expression in ArcMap 10.2.1.



I want to show two labels per polygon, but only when there are two labels to show.
Every polygon has at least one label (Veg_Dominant), but some polygons also have a second (Veg_codominant). I want polygons with only one label to show this one label, and polygons with two labels to show both with a '+' sign in between.



This is how I entered it in the label expression:



enter image description here



This is how it looks in the map:



enter image description here



is there a way to only show the '+' sign when there is more than one label to show?










share|improve this question















I am having problems with label expression in ArcMap 10.2.1.



I want to show two labels per polygon, but only when there are two labels to show.
Every polygon has at least one label (Veg_Dominant), but some polygons also have a second (Veg_codominant). I want polygons with only one label to show this one label, and polygons with two labels to show both with a '+' sign in between.



This is how I entered it in the label expression:



enter image description here



This is how it looks in the map:



enter image description here



is there a way to only show the '+' sign when there is more than one label to show?







arcgis-desktop arcmap labeling if-else






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 19:21









ahmadhanb

21.6k31951




21.6k31951










asked Nov 20 at 10:51









Tom van Heusden

353




353












  • Click on Help in the lower middle of your label expression dialog. The If-Else statement is one of the examples there.
    – Matte
    Nov 20 at 10:58


















  • Click on Help in the lower middle of your label expression dialog. The If-Else statement is one of the examples there.
    – Matte
    Nov 20 at 10:58
















Click on Help in the lower middle of your label expression dialog. The If-Else statement is one of the examples there.
– Matte
Nov 20 at 10:58




Click on Help in the lower middle of your label expression dialog. The If-Else statement is one of the examples there.
– Matte
Nov 20 at 10:58










3 Answers
3






active

oldest

votes


















5














In the Label Expression, switch to "advanced", select VBScript as Parser, and paste this code:



Function FindLabel ( [veg_dominant] , [veg_codominant]  )
if [veg_codominant] <> " " then
FindLabel = [veg_dominant] + "+" + [veg_codominant]
else
FindLabel = [veg_dominant]
end if
End Function


This expression means: if veg_codominant has values, then the label will be field1+field2, otherwise if the field is empty, use only field1 as the label






share|improve this answer

















  • 1




    Thanks a lot! Worked out great!
    – Tom van Heusden
    Nov 20 at 14:22



















3














Here is the Python version after selecting advanced in Label Expression:



def FindLabel ( [veg_dominant] , [veg_codominant]):
if [veg_codominant] != ' ':
return [veg_dominant] + "+"+ [veg_codominant]
else:
return [veg_dominant]





share|improve this answer





























    0














    I think the most pythonic way of doing this is to use filter and str.join built-in methods, which lets you to add as many fields as you like without worrying about putting delimiters in between and checking if the value is False, for example:



    def FindLabel ([veg_dominant], [veg_codominant]):
    return "+".join(filter(None, ([veg_dominant], [veg_codominant])))





    share|improve this answer





















      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "79"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f303306%2fwriting-label-expression-with-arcmap-and-if-then-statement%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      5














      In the Label Expression, switch to "advanced", select VBScript as Parser, and paste this code:



      Function FindLabel ( [veg_dominant] , [veg_codominant]  )
      if [veg_codominant] <> " " then
      FindLabel = [veg_dominant] + "+" + [veg_codominant]
      else
      FindLabel = [veg_dominant]
      end if
      End Function


      This expression means: if veg_codominant has values, then the label will be field1+field2, otherwise if the field is empty, use only field1 as the label






      share|improve this answer

















      • 1




        Thanks a lot! Worked out great!
        – Tom van Heusden
        Nov 20 at 14:22
















      5














      In the Label Expression, switch to "advanced", select VBScript as Parser, and paste this code:



      Function FindLabel ( [veg_dominant] , [veg_codominant]  )
      if [veg_codominant] <> " " then
      FindLabel = [veg_dominant] + "+" + [veg_codominant]
      else
      FindLabel = [veg_dominant]
      end if
      End Function


      This expression means: if veg_codominant has values, then the label will be field1+field2, otherwise if the field is empty, use only field1 as the label






      share|improve this answer

















      • 1




        Thanks a lot! Worked out great!
        – Tom van Heusden
        Nov 20 at 14:22














      5












      5








      5






      In the Label Expression, switch to "advanced", select VBScript as Parser, and paste this code:



      Function FindLabel ( [veg_dominant] , [veg_codominant]  )
      if [veg_codominant] <> " " then
      FindLabel = [veg_dominant] + "+" + [veg_codominant]
      else
      FindLabel = [veg_dominant]
      end if
      End Function


      This expression means: if veg_codominant has values, then the label will be field1+field2, otherwise if the field is empty, use only field1 as the label






      share|improve this answer












      In the Label Expression, switch to "advanced", select VBScript as Parser, and paste this code:



      Function FindLabel ( [veg_dominant] , [veg_codominant]  )
      if [veg_codominant] <> " " then
      FindLabel = [veg_dominant] + "+" + [veg_codominant]
      else
      FindLabel = [veg_dominant]
      end if
      End Function


      This expression means: if veg_codominant has values, then the label will be field1+field2, otherwise if the field is empty, use only field1 as the label







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Nov 20 at 11:04









      Vale

      828519




      828519








      • 1




        Thanks a lot! Worked out great!
        – Tom van Heusden
        Nov 20 at 14:22














      • 1




        Thanks a lot! Worked out great!
        – Tom van Heusden
        Nov 20 at 14:22








      1




      1




      Thanks a lot! Worked out great!
      – Tom van Heusden
      Nov 20 at 14:22




      Thanks a lot! Worked out great!
      – Tom van Heusden
      Nov 20 at 14:22













      3














      Here is the Python version after selecting advanced in Label Expression:



      def FindLabel ( [veg_dominant] , [veg_codominant]):
      if [veg_codominant] != ' ':
      return [veg_dominant] + "+"+ [veg_codominant]
      else:
      return [veg_dominant]





      share|improve this answer


























        3














        Here is the Python version after selecting advanced in Label Expression:



        def FindLabel ( [veg_dominant] , [veg_codominant]):
        if [veg_codominant] != ' ':
        return [veg_dominant] + "+"+ [veg_codominant]
        else:
        return [veg_dominant]





        share|improve this answer
























          3












          3








          3






          Here is the Python version after selecting advanced in Label Expression:



          def FindLabel ( [veg_dominant] , [veg_codominant]):
          if [veg_codominant] != ' ':
          return [veg_dominant] + "+"+ [veg_codominant]
          else:
          return [veg_dominant]





          share|improve this answer












          Here is the Python version after selecting advanced in Label Expression:



          def FindLabel ( [veg_dominant] , [veg_codominant]):
          if [veg_codominant] != ' ':
          return [veg_dominant] + "+"+ [veg_codominant]
          else:
          return [veg_dominant]






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 at 11:21









          ahmadhanb

          21.6k31951




          21.6k31951























              0














              I think the most pythonic way of doing this is to use filter and str.join built-in methods, which lets you to add as many fields as you like without worrying about putting delimiters in between and checking if the value is False, for example:



              def FindLabel ([veg_dominant], [veg_codominant]):
              return "+".join(filter(None, ([veg_dominant], [veg_codominant])))





              share|improve this answer


























                0














                I think the most pythonic way of doing this is to use filter and str.join built-in methods, which lets you to add as many fields as you like without worrying about putting delimiters in between and checking if the value is False, for example:



                def FindLabel ([veg_dominant], [veg_codominant]):
                return "+".join(filter(None, ([veg_dominant], [veg_codominant])))





                share|improve this answer
























                  0












                  0








                  0






                  I think the most pythonic way of doing this is to use filter and str.join built-in methods, which lets you to add as many fields as you like without worrying about putting delimiters in between and checking if the value is False, for example:



                  def FindLabel ([veg_dominant], [veg_codominant]):
                  return "+".join(filter(None, ([veg_dominant], [veg_codominant])))





                  share|improve this answer












                  I think the most pythonic way of doing this is to use filter and str.join built-in methods, which lets you to add as many fields as you like without worrying about putting delimiters in between and checking if the value is False, for example:



                  def FindLabel ([veg_dominant], [veg_codominant]):
                  return "+".join(filter(None, ([veg_dominant], [veg_codominant])))






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 21 at 8:22









                  fatih_dur

                  3,5502927




                  3,5502927






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f303306%2fwriting-label-expression-with-arcmap-and-if-then-statement%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Costa Masnaga

                      Fotorealismo

                      Sidney Franklin