QGIS - How to differently colorize labels from two separate fields using color expression script?
I have 2 fields, I concatenate them [concat(to_string(field1), ' ', to_string(field2))
] to show their labels side-by-side.
Is it possible to colorize from "text color expression" (using some scripts) first label in "color1" and second label in "color2"?
Clarification
I want the final result to be like below ("field1" data to be shown in red, "field2" data to be shown in green)
qgis labeling color expression
add a comment |
I have 2 fields, I concatenate them [concat(to_string(field1), ' ', to_string(field2))
] to show their labels side-by-side.
Is it possible to colorize from "text color expression" (using some scripts) first label in "color1" and second label in "color2"?
Clarification
I want the final result to be like below ("field1" data to be shown in red, "field2" data to be shown in green)
qgis labeling color expression
add a comment |
I have 2 fields, I concatenate them [concat(to_string(field1), ' ', to_string(field2))
] to show their labels side-by-side.
Is it possible to colorize from "text color expression" (using some scripts) first label in "color1" and second label in "color2"?
Clarification
I want the final result to be like below ("field1" data to be shown in red, "field2" data to be shown in green)
qgis labeling color expression
I have 2 fields, I concatenate them [concat(to_string(field1), ' ', to_string(field2))
] to show their labels side-by-side.
Is it possible to colorize from "text color expression" (using some scripts) first label in "color1" and second label in "color2"?
Clarification
I want the final result to be like below ("field1" data to be shown in red, "field2" data to be shown in green)
qgis labeling color expression
qgis labeling color expression
edited Jan 25 at 7:42
Vitruvius
asked Jan 24 at 8:57
VitruviusVitruvius
499211
499211
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You may be able to use Symbology
, rather than Label
.
(1) Choose Symbology
tab and add two layers of Centroid fill
with the Font marker
type. Give negative offset (e.g. -10.0mm) to red, and positive offset (e.g. 10.0mm) to green.
(2) Highlight Font marker
. Scroll down a little bit further, and click on the Data defined override
(a small pull-down menu). Select each of your field for the corresponding color.
(3) You will probably have to adjust font size and offset value, by visually checking what you see on the map.
Yeah, not bad option. It is similar to "rule-based labeling" that I did. Thank you for your effort. I just want to find out if that "color expression" is capable for that or not. I failed but maybe someone (more advanced in scripting) knows the way.
– Vitruvius
Jan 24 at 11:27
1
AFAIK the label color is applied to the entire label, there's no way to apply different colors to different parts of a label. It's possible for label items in the print layout, but not for map labels. For example, here's a print layout label with red and green text: <p style="color:red">red text</p><p style="color:green">green text</p>
– csk
Jan 24 at 18:19
add a comment |
EDIT: I misread your question, my apologies. I thought you wanted to select a color using an expression which depended on the value of two fields. Sorry about that.
Yes you can.
In the label options for the layer open the color selectio box. You don't need to set any colours here just find the colours you want and copy their hex codes into notepad:
In the Text tab for labelling add an expression for the color value by clicking the box shown below and choosing Edit:
Then add an expression like the following:
CASE
WHEN "Field1" = 'value1' AND "Field2" = 'value2' THEN '#00ab98'
WHEN "Field2" = 'value3' AND "Field2" = 'value4' THEN '#625974'
END
WHEN "Field1" = 'value1' AND "Field2" = 'value2' THEN '#00ab98' that makes both fields (where their labels appear together) to be #00ab98. But I want different color for each label in all cases.
– Vitruvius
Jan 24 at 9:28
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%2f309717%2fqgis-how-to-differently-colorize-labels-from-two-separate-fields-using-color-e%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You may be able to use Symbology
, rather than Label
.
(1) Choose Symbology
tab and add two layers of Centroid fill
with the Font marker
type. Give negative offset (e.g. -10.0mm) to red, and positive offset (e.g. 10.0mm) to green.
(2) Highlight Font marker
. Scroll down a little bit further, and click on the Data defined override
(a small pull-down menu). Select each of your field for the corresponding color.
(3) You will probably have to adjust font size and offset value, by visually checking what you see on the map.
Yeah, not bad option. It is similar to "rule-based labeling" that I did. Thank you for your effort. I just want to find out if that "color expression" is capable for that or not. I failed but maybe someone (more advanced in scripting) knows the way.
– Vitruvius
Jan 24 at 11:27
1
AFAIK the label color is applied to the entire label, there's no way to apply different colors to different parts of a label. It's possible for label items in the print layout, but not for map labels. For example, here's a print layout label with red and green text: <p style="color:red">red text</p><p style="color:green">green text</p>
– csk
Jan 24 at 18:19
add a comment |
You may be able to use Symbology
, rather than Label
.
(1) Choose Symbology
tab and add two layers of Centroid fill
with the Font marker
type. Give negative offset (e.g. -10.0mm) to red, and positive offset (e.g. 10.0mm) to green.
(2) Highlight Font marker
. Scroll down a little bit further, and click on the Data defined override
(a small pull-down menu). Select each of your field for the corresponding color.
(3) You will probably have to adjust font size and offset value, by visually checking what you see on the map.
Yeah, not bad option. It is similar to "rule-based labeling" that I did. Thank you for your effort. I just want to find out if that "color expression" is capable for that or not. I failed but maybe someone (more advanced in scripting) knows the way.
– Vitruvius
Jan 24 at 11:27
1
AFAIK the label color is applied to the entire label, there's no way to apply different colors to different parts of a label. It's possible for label items in the print layout, but not for map labels. For example, here's a print layout label with red and green text: <p style="color:red">red text</p><p style="color:green">green text</p>
– csk
Jan 24 at 18:19
add a comment |
You may be able to use Symbology
, rather than Label
.
(1) Choose Symbology
tab and add two layers of Centroid fill
with the Font marker
type. Give negative offset (e.g. -10.0mm) to red, and positive offset (e.g. 10.0mm) to green.
(2) Highlight Font marker
. Scroll down a little bit further, and click on the Data defined override
(a small pull-down menu). Select each of your field for the corresponding color.
(3) You will probably have to adjust font size and offset value, by visually checking what you see on the map.
You may be able to use Symbology
, rather than Label
.
(1) Choose Symbology
tab and add two layers of Centroid fill
with the Font marker
type. Give negative offset (e.g. -10.0mm) to red, and positive offset (e.g. 10.0mm) to green.
(2) Highlight Font marker
. Scroll down a little bit further, and click on the Data defined override
(a small pull-down menu). Select each of your field for the corresponding color.
(3) You will probably have to adjust font size and offset value, by visually checking what you see on the map.
answered Jan 24 at 10:46
KazuhitoKazuhito
16.1k41883
16.1k41883
Yeah, not bad option. It is similar to "rule-based labeling" that I did. Thank you for your effort. I just want to find out if that "color expression" is capable for that or not. I failed but maybe someone (more advanced in scripting) knows the way.
– Vitruvius
Jan 24 at 11:27
1
AFAIK the label color is applied to the entire label, there's no way to apply different colors to different parts of a label. It's possible for label items in the print layout, but not for map labels. For example, here's a print layout label with red and green text: <p style="color:red">red text</p><p style="color:green">green text</p>
– csk
Jan 24 at 18:19
add a comment |
Yeah, not bad option. It is similar to "rule-based labeling" that I did. Thank you for your effort. I just want to find out if that "color expression" is capable for that or not. I failed but maybe someone (more advanced in scripting) knows the way.
– Vitruvius
Jan 24 at 11:27
1
AFAIK the label color is applied to the entire label, there's no way to apply different colors to different parts of a label. It's possible for label items in the print layout, but not for map labels. For example, here's a print layout label with red and green text: <p style="color:red">red text</p><p style="color:green">green text</p>
– csk
Jan 24 at 18:19
Yeah, not bad option. It is similar to "rule-based labeling" that I did. Thank you for your effort. I just want to find out if that "color expression" is capable for that or not. I failed but maybe someone (more advanced in scripting) knows the way.
– Vitruvius
Jan 24 at 11:27
Yeah, not bad option. It is similar to "rule-based labeling" that I did. Thank you for your effort. I just want to find out if that "color expression" is capable for that or not. I failed but maybe someone (more advanced in scripting) knows the way.
– Vitruvius
Jan 24 at 11:27
1
1
AFAIK the label color is applied to the entire label, there's no way to apply different colors to different parts of a label. It's possible for label items in the print layout, but not for map labels. For example, here's a print layout label with red and green text: <p style="color:red">red text</p><p style="color:green">green text</p>
– csk
Jan 24 at 18:19
AFAIK the label color is applied to the entire label, there's no way to apply different colors to different parts of a label. It's possible for label items in the print layout, but not for map labels. For example, here's a print layout label with red and green text: <p style="color:red">red text</p><p style="color:green">green text</p>
– csk
Jan 24 at 18:19
add a comment |
EDIT: I misread your question, my apologies. I thought you wanted to select a color using an expression which depended on the value of two fields. Sorry about that.
Yes you can.
In the label options for the layer open the color selectio box. You don't need to set any colours here just find the colours you want and copy their hex codes into notepad:
In the Text tab for labelling add an expression for the color value by clicking the box shown below and choosing Edit:
Then add an expression like the following:
CASE
WHEN "Field1" = 'value1' AND "Field2" = 'value2' THEN '#00ab98'
WHEN "Field2" = 'value3' AND "Field2" = 'value4' THEN '#625974'
END
WHEN "Field1" = 'value1' AND "Field2" = 'value2' THEN '#00ab98' that makes both fields (where their labels appear together) to be #00ab98. But I want different color for each label in all cases.
– Vitruvius
Jan 24 at 9:28
add a comment |
EDIT: I misread your question, my apologies. I thought you wanted to select a color using an expression which depended on the value of two fields. Sorry about that.
Yes you can.
In the label options for the layer open the color selectio box. You don't need to set any colours here just find the colours you want and copy their hex codes into notepad:
In the Text tab for labelling add an expression for the color value by clicking the box shown below and choosing Edit:
Then add an expression like the following:
CASE
WHEN "Field1" = 'value1' AND "Field2" = 'value2' THEN '#00ab98'
WHEN "Field2" = 'value3' AND "Field2" = 'value4' THEN '#625974'
END
WHEN "Field1" = 'value1' AND "Field2" = 'value2' THEN '#00ab98' that makes both fields (where their labels appear together) to be #00ab98. But I want different color for each label in all cases.
– Vitruvius
Jan 24 at 9:28
add a comment |
EDIT: I misread your question, my apologies. I thought you wanted to select a color using an expression which depended on the value of two fields. Sorry about that.
Yes you can.
In the label options for the layer open the color selectio box. You don't need to set any colours here just find the colours you want and copy their hex codes into notepad:
In the Text tab for labelling add an expression for the color value by clicking the box shown below and choosing Edit:
Then add an expression like the following:
CASE
WHEN "Field1" = 'value1' AND "Field2" = 'value2' THEN '#00ab98'
WHEN "Field2" = 'value3' AND "Field2" = 'value4' THEN '#625974'
END
EDIT: I misread your question, my apologies. I thought you wanted to select a color using an expression which depended on the value of two fields. Sorry about that.
Yes you can.
In the label options for the layer open the color selectio box. You don't need to set any colours here just find the colours you want and copy their hex codes into notepad:
In the Text tab for labelling add an expression for the color value by clicking the box shown below and choosing Edit:
Then add an expression like the following:
CASE
WHEN "Field1" = 'value1' AND "Field2" = 'value2' THEN '#00ab98'
WHEN "Field2" = 'value3' AND "Field2" = 'value4' THEN '#625974'
END
answered Jan 24 at 9:18
TeddyTedTedTeddyTedTed
80819
80819
WHEN "Field1" = 'value1' AND "Field2" = 'value2' THEN '#00ab98' that makes both fields (where their labels appear together) to be #00ab98. But I want different color for each label in all cases.
– Vitruvius
Jan 24 at 9:28
add a comment |
WHEN "Field1" = 'value1' AND "Field2" = 'value2' THEN '#00ab98' that makes both fields (where their labels appear together) to be #00ab98. But I want different color for each label in all cases.
– Vitruvius
Jan 24 at 9:28
WHEN "Field1" = 'value1' AND "Field2" = 'value2' THEN '#00ab98' that makes both fields (where their labels appear together) to be #00ab98. But I want different color for each label in all cases.
– Vitruvius
Jan 24 at 9:28
WHEN "Field1" = 'value1' AND "Field2" = 'value2' THEN '#00ab98' that makes both fields (where their labels appear together) to be #00ab98. But I want different color for each label in all cases.
– Vitruvius
Jan 24 at 9:28
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.
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%2f309717%2fqgis-how-to-differently-colorize-labels-from-two-separate-fields-using-color-e%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