QGIS - How to color labels from different fields using color expression?












2















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?



enter image description here



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")



enter image description here










share|improve this question





























    2















    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?



    enter image description here



    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")



    enter image description here










    share|improve this question



























      2












      2








      2








      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?



      enter image description here



      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")



      enter image description here










      share|improve this question
















      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?



      enter image description here



      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")



      enter image description here







      qgis labeling color expression






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 hours ago







      Vitruvius

















      asked 2 hours ago









      VitruviusVitruvius

      38229




      38229






















          2 Answers
          2






          active

          oldest

          votes


















          2














          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.



          enter image description here



          (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.



          enter image description here



          (3) You will probably have to adjust font size and offset value, by visually checking what you see on the map.



          enter image description here






          share|improve this answer
























          • 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



















          1














          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:



          enter image description here



          In the Text tab for labelling add an expression for the color value by clicking the box shown below and choosing Edit:



          enter image description here



          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





          share|improve this answer
























          • 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













          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
          });


          }
          });














          draft saved

          draft discarded


















          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









          2














          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.



          enter image description here



          (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.



          enter image description here



          (3) You will probably have to adjust font size and offset value, by visually checking what you see on the map.



          enter image description here






          share|improve this answer
























          • 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
















          2














          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.



          enter image description here



          (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.



          enter image description here



          (3) You will probably have to adjust font size and offset value, by visually checking what you see on the map.



          enter image description here






          share|improve this answer
























          • 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














          2












          2








          2







          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.



          enter image description here



          (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.



          enter image description here



          (3) You will probably have to adjust font size and offset value, by visually checking what you see on the map.



          enter image description here






          share|improve this answer













          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.



          enter image description here



          (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.



          enter image description here



          (3) You will probably have to adjust font size and offset value, by visually checking what you see on the map.



          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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



















          • 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













          1














          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:



          enter image description here



          In the Text tab for labelling add an expression for the color value by clicking the box shown below and choosing Edit:



          enter image description here



          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





          share|improve this answer
























          • 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


















          1














          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:



          enter image description here



          In the Text tab for labelling add an expression for the color value by clicking the box shown below and choosing Edit:



          enter image description here



          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





          share|improve this answer
























          • 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
















          1












          1








          1







          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:



          enter image description here



          In the Text tab for labelling add an expression for the color value by clicking the box shown below and choosing Edit:



          enter image description here



          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





          share|improve this answer













          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:



          enter image description here



          In the Text tab for labelling add an expression for the color value by clicking the box shown below and choosing Edit:



          enter image description here



          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






          share|improve this answer












          share|improve this answer



          share|improve this answer










          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





















          • 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




















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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

          How to label and detect the document text images

          Vallis Paradisi

          Tabula Rosettana