Writing label expression with ArcMap and If then Statement?
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:
This is how it looks in the map:
is there a way to only show the '+' sign when there is more than one label to show?
arcgis-desktop arcmap labeling if-else
add a comment |
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:
This is how it looks in the map:
is there a way to only show the '+' sign when there is more than one label to show?
arcgis-desktop arcmap labeling if-else
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
add a comment |
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:
This is how it looks in the map:
is there a way to only show the '+' sign when there is more than one label to show?
arcgis-desktop arcmap labeling if-else
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:
This is how it looks in the map:
is there a way to only show the '+' sign when there is more than one label to show?
arcgis-desktop arcmap labeling if-else
arcgis-desktop arcmap labeling if-else
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
add a comment |
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
add a comment |
3 Answers
3
active
oldest
votes
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
1
Thanks a lot! Worked out great!
– Tom van Heusden
Nov 20 at 14:22
add a comment |
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]
add a comment |
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])))
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
1
Thanks a lot! Worked out great!
– Tom van Heusden
Nov 20 at 14:22
add a comment |
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
1
Thanks a lot! Worked out great!
– Tom van Heusden
Nov 20 at 14:22
add a comment |
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
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
answered Nov 20 at 11:04
Vale
828519
828519
1
Thanks a lot! Worked out great!
– Tom van Heusden
Nov 20 at 14:22
add a comment |
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
add a comment |
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]
add a comment |
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]
add a comment |
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]
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]
answered Nov 20 at 11:21
ahmadhanb
21.6k31951
21.6k31951
add a comment |
add a comment |
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])))
add a comment |
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])))
add a comment |
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])))
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])))
answered Nov 21 at 8:22
fatih_dur
3,5502927
3,5502927
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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