Writing label expression with ArcMap and If then Statement?











up vote
2
down vote

favorite
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
























  • Click on Help in the lower middle of your label expression dialog. The If-Else statement is one of the examples there.
    – Matte
    2 days ago















up vote
2
down vote

favorite
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
























  • Click on Help in the lower middle of your label expression dialog. The If-Else statement is one of the examples there.
    – Matte
    2 days ago













up vote
2
down vote

favorite
1









up vote
2
down vote

favorite
1






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 2 days ago









ahmadhanb

20.9k31849




20.9k31849










asked 2 days ago









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
    2 days ago


















  • Click on Help in the lower middle of your label expression dialog. The If-Else statement is one of the examples there.
    – Matte
    2 days ago
















Click on Help in the lower middle of your label expression dialog. The If-Else statement is one of the examples there.
– Matte
2 days ago




Click on Help in the lower middle of your label expression dialog. The If-Else statement is one of the examples there.
– Matte
2 days ago










3 Answers
3






active

oldest

votes

















up vote
5
down vote



accepted










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
    2 days ago


















up vote
3
down vote













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




























    up vote
    0
    down vote













    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',
      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








      up vote
      5
      down vote



      accepted










      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
        2 days ago















      up vote
      5
      down vote



      accepted










      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
        2 days ago













      up vote
      5
      down vote



      accepted







      up vote
      5
      down vote



      accepted






      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 2 days ago









      Vale

      726519




      726519








      • 1




        Thanks a lot! Worked out great!
        – Tom van Heusden
        2 days ago














      • 1




        Thanks a lot! Worked out great!
        – Tom van Heusden
        2 days ago








      1




      1




      Thanks a lot! Worked out great!
      – Tom van Heusden
      2 days ago




      Thanks a lot! Worked out great!
      – Tom van Heusden
      2 days ago












      up vote
      3
      down vote













      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

























        up vote
        3
        down vote













        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























          up vote
          3
          down vote










          up vote
          3
          down vote









          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 2 days ago









          ahmadhanb

          20.9k31849




          20.9k31849






















              up vote
              0
              down vote













              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

























                up vote
                0
                down vote













                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























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  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 yesterday









                  fatih_dur

                  3,5512927




                  3,5512927






























                       

                      draft saved


                      draft discarded



















































                       


                      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

                      Ellipse (mathématiques)

                      Quarter-circle Tiles

                      Mont Emei