QGIS - How to color labels from different fields using color expression?
I have 2 fields, I concatenate them to show side-by-side but I want to give to each of them different color using color expression.
Is it possible?
p.s. I did coloring using rule-based labeling but I am curious if it is possible using single expression (like: "when case", or "if").
Update
I want the final result to be like below (reds are from "field1", greens from "field2")
qgis labeling color expression
add a comment |
I have 2 fields, I concatenate them to show side-by-side but I want to give to each of them different color using color expression.
Is it possible?
p.s. I did coloring using rule-based labeling but I am curious if it is possible using single expression (like: "when case", or "if").
Update
I want the final result to be like below (reds are from "field1", greens from "field2")
qgis labeling color expression
add a comment |
I have 2 fields, I concatenate them to show side-by-side but I want to give to each of them different color using color expression.
Is it possible?
p.s. I did coloring using rule-based labeling but I am curious if it is possible using single expression (like: "when case", or "if").
Update
I want the final result to be like below (reds are from "field1", greens from "field2")
qgis labeling color expression
I have 2 fields, I concatenate them to show side-by-side but I want to give to each of them different color using color expression.
Is it possible?
p.s. I did coloring using rule-based labeling but I am curious if it is possible using single expression (like: "when case", or "if").
Update
I want the final result to be like below (reds are from "field1", greens from "field2")
qgis labeling color expression
qgis labeling color expression
edited 2 hours ago
Vitruvius
asked 2 hours ago
VitruviusVitruvius
38229
38229
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
17 mins ago
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
2 hours ago
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-color-labels-from-different-fields-using-color-expression%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
17 mins ago
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
17 mins ago
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 59 mins ago
KazuhitoKazuhito
14.8k31677
14.8k31677
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
17 mins ago
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
17 mins ago
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
17 mins ago
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
17 mins ago
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
2 hours ago
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
2 hours ago
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 2 hours ago
TeddyTedTedTeddyTedTed
58319
58319
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
2 hours ago
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
2 hours ago
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
2 hours ago
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
2 hours ago
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-color-labels-from-different-fields-using-color-expression%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