Writing label expression with ArcMap and If then Statement?
up vote
2
down vote
favorite
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 |
up vote
2
down vote
favorite
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 |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
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
21k31849
21k31849
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
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
1
Thanks a lot! Worked out great!
– Tom van Heusden
Nov 20 at 14:22
add a comment |
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]
add a comment |
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])))
add a comment |
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
1
Thanks a lot! Worked out great!
– Tom van Heusden
Nov 20 at 14:22
add a comment |
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
1
Thanks a lot! Worked out great!
– Tom van Heusden
Nov 20 at 14:22
add a comment |
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
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
728519
728519
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 |
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]
add a comment |
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]
add a comment |
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]
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
21k31849
21k31849
add a comment |
add a comment |
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])))
add a comment |
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])))
add a comment |
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])))
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,5512927
3,5512927
add a comment |
add a comment |
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