Assign a specific color to vector layer based on RGB codes in attribute table












3















I use QGIS and have a geological map for a large area. I present this after ID codes based on the geology ("Geokartnr" in photo).



I want to use international/nation color codes for each rock type, this way it will be comparable to other peoples work. The international colors is already added to the attribute table as a RGB code ("RGBfargko"). Is there any way I can sort/present the maps by "geokartnr" code and present this by the color codes in the RGB codes in the attribute table? Or do I need to change all colors manually?



Screenshot of the attribute table










share|improve this question









New contributor




Casairo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Be aware that by using an expression to set the color as stated answer below you wont be able to automatically generate a legend.... (so the problem is you either set the color manually OR create the legend manually....)

    – J.R
    yesterday











  • @J.R Good point, I think its kind of bug, because I suppose that it will generate legend if you use Categorized symbology (with rgb field as category). You can manually change a symbol of every each category, but if the data defined values are set for color, the value is just not taken from the expression. Or I am missing something?

    – Oto Kaláb
    yesterday


















3















I use QGIS and have a geological map for a large area. I present this after ID codes based on the geology ("Geokartnr" in photo).



I want to use international/nation color codes for each rock type, this way it will be comparable to other peoples work. The international colors is already added to the attribute table as a RGB code ("RGBfargko"). Is there any way I can sort/present the maps by "geokartnr" code and present this by the color codes in the RGB codes in the attribute table? Or do I need to change all colors manually?



Screenshot of the attribute table










share|improve this question









New contributor




Casairo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Be aware that by using an expression to set the color as stated answer below you wont be able to automatically generate a legend.... (so the problem is you either set the color manually OR create the legend manually....)

    – J.R
    yesterday











  • @J.R Good point, I think its kind of bug, because I suppose that it will generate legend if you use Categorized symbology (with rgb field as category). You can manually change a symbol of every each category, but if the data defined values are set for color, the value is just not taken from the expression. Or I am missing something?

    – Oto Kaláb
    yesterday
















3












3








3


1






I use QGIS and have a geological map for a large area. I present this after ID codes based on the geology ("Geokartnr" in photo).



I want to use international/nation color codes for each rock type, this way it will be comparable to other peoples work. The international colors is already added to the attribute table as a RGB code ("RGBfargko"). Is there any way I can sort/present the maps by "geokartnr" code and present this by the color codes in the RGB codes in the attribute table? Or do I need to change all colors manually?



Screenshot of the attribute table










share|improve this question









New contributor




Casairo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I use QGIS and have a geological map for a large area. I present this after ID codes based on the geology ("Geokartnr" in photo).



I want to use international/nation color codes for each rock type, this way it will be comparable to other peoples work. The international colors is already added to the attribute table as a RGB code ("RGBfargko"). Is there any way I can sort/present the maps by "geokartnr" code and present this by the color codes in the RGB codes in the attribute table? Or do I need to change all colors manually?



Screenshot of the attribute table







qgis attribute-table visualisation vector-layer






share|improve this question









New contributor




Casairo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Casairo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited yesterday









Ian Turton

49.9k547115




49.9k547115






New contributor




Casairo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked yesterday









CasairoCasairo

162




162




New contributor




Casairo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Casairo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Casairo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • Be aware that by using an expression to set the color as stated answer below you wont be able to automatically generate a legend.... (so the problem is you either set the color manually OR create the legend manually....)

    – J.R
    yesterday











  • @J.R Good point, I think its kind of bug, because I suppose that it will generate legend if you use Categorized symbology (with rgb field as category). You can manually change a symbol of every each category, but if the data defined values are set for color, the value is just not taken from the expression. Or I am missing something?

    – Oto Kaláb
    yesterday





















  • Be aware that by using an expression to set the color as stated answer below you wont be able to automatically generate a legend.... (so the problem is you either set the color manually OR create the legend manually....)

    – J.R
    yesterday











  • @J.R Good point, I think its kind of bug, because I suppose that it will generate legend if you use Categorized symbology (with rgb field as category). You can manually change a symbol of every each category, but if the data defined values are set for color, the value is just not taken from the expression. Or I am missing something?

    – Oto Kaláb
    yesterday



















Be aware that by using an expression to set the color as stated answer below you wont be able to automatically generate a legend.... (so the problem is you either set the color manually OR create the legend manually....)

– J.R
yesterday





Be aware that by using an expression to set the color as stated answer below you wont be able to automatically generate a legend.... (so the problem is you either set the color manually OR create the legend manually....)

– J.R
yesterday













@J.R Good point, I think its kind of bug, because I suppose that it will generate legend if you use Categorized symbology (with rgb field as category). You can manually change a symbol of every each category, but if the data defined values are set for color, the value is just not taken from the expression. Or I am missing something?

– Oto Kaláb
yesterday







@J.R Good point, I think its kind of bug, because I suppose that it will generate legend if you use Categorized symbology (with rgb field as category). You can manually change a symbol of every each category, but if the data defined values are set for color, the value is just not taken from the expression. Or I am missing something?

– Oto Kaláb
yesterday












3 Answers
3






active

oldest

votes


















5














In the layer styles panel if you click on simple marker, there is a small box to the right of the fill color combo box - if you click on it you can select edit from the menu and enter the expression editor.



enter image description here
You will need an expression like this, to convert your string's spaces to commas and then into a colour:



color_rgb( replace("rgbfargeko",' ',','))


Then click ok and your colors should show up.






share|improve this answer


























  • You missed a closing bracket ).

    – ahmadhanb
    22 hours ago



















3














AS @J. Monticolo supposed, use Data defined expression in symbology properties.



enter image description here



For expression you can simply use:



replace("rgbfargko",' ',',')


Which takse "rgbfargko" string and replace spaces whit commas for proper color formatting. See:



enter image description here



enter image description here






share|improve this answer































    2














    In the layer properties, in the symbology tab, define the color by an expression (link to the QGIS doc) :



    color_rgb(
    array_get(string_to_array("rgbfargko", ' '), 0),
    array_get(string_to_array("rgbfargko", ' '), 1),
    array_get(string_to_array("rgbfargko", ' '), 2)
    )


    Explanation of the code :



    1- function string_to_array : transform the field data into an array by splitting at the white space character ;
    2- function array_get : get elements of the array, the first item has an index of 0 ;
    3- function color_rgb : with 3 arguments (R, G, B), this function return a QGIS color.



    EDIT
    The solution of @Ian Turton is more visual and simple !






    share|improve this answer

























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


      }
      });






      Casairo is a new contributor. Be nice, and check out our Code of Conduct.










      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f316218%2fassign-a-specific-color-to-vector-layer-based-on-rgb-codes-in-attribute-table%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









      5














      In the layer styles panel if you click on simple marker, there is a small box to the right of the fill color combo box - if you click on it you can select edit from the menu and enter the expression editor.



      enter image description here
      You will need an expression like this, to convert your string's spaces to commas and then into a colour:



      color_rgb( replace("rgbfargeko",' ',','))


      Then click ok and your colors should show up.






      share|improve this answer


























      • You missed a closing bracket ).

        – ahmadhanb
        22 hours ago
















      5














      In the layer styles panel if you click on simple marker, there is a small box to the right of the fill color combo box - if you click on it you can select edit from the menu and enter the expression editor.



      enter image description here
      You will need an expression like this, to convert your string's spaces to commas and then into a colour:



      color_rgb( replace("rgbfargeko",' ',','))


      Then click ok and your colors should show up.






      share|improve this answer


























      • You missed a closing bracket ).

        – ahmadhanb
        22 hours ago














      5












      5








      5







      In the layer styles panel if you click on simple marker, there is a small box to the right of the fill color combo box - if you click on it you can select edit from the menu and enter the expression editor.



      enter image description here
      You will need an expression like this, to convert your string's spaces to commas and then into a colour:



      color_rgb( replace("rgbfargeko",' ',','))


      Then click ok and your colors should show up.






      share|improve this answer















      In the layer styles panel if you click on simple marker, there is a small box to the right of the fill color combo box - if you click on it you can select edit from the menu and enter the expression editor.



      enter image description here
      You will need an expression like this, to convert your string's spaces to commas and then into a colour:



      color_rgb( replace("rgbfargeko",' ',','))


      Then click ok and your colors should show up.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited 15 hours ago

























      answered yesterday









      Ian TurtonIan Turton

      49.9k547115




      49.9k547115













      • You missed a closing bracket ).

        – ahmadhanb
        22 hours ago



















      • You missed a closing bracket ).

        – ahmadhanb
        22 hours ago

















      You missed a closing bracket ).

      – ahmadhanb
      22 hours ago





      You missed a closing bracket ).

      – ahmadhanb
      22 hours ago













      3














      AS @J. Monticolo supposed, use Data defined expression in symbology properties.



      enter image description here



      For expression you can simply use:



      replace("rgbfargko",' ',',')


      Which takse "rgbfargko" string and replace spaces whit commas for proper color formatting. See:



      enter image description here



      enter image description here






      share|improve this answer




























        3














        AS @J. Monticolo supposed, use Data defined expression in symbology properties.



        enter image description here



        For expression you can simply use:



        replace("rgbfargko",' ',',')


        Which takse "rgbfargko" string and replace spaces whit commas for proper color formatting. See:



        enter image description here



        enter image description here






        share|improve this answer


























          3












          3








          3







          AS @J. Monticolo supposed, use Data defined expression in symbology properties.



          enter image description here



          For expression you can simply use:



          replace("rgbfargko",' ',',')


          Which takse "rgbfargko" string and replace spaces whit commas for proper color formatting. See:



          enter image description here



          enter image description here






          share|improve this answer













          AS @J. Monticolo supposed, use Data defined expression in symbology properties.



          enter image description here



          For expression you can simply use:



          replace("rgbfargko",' ',',')


          Which takse "rgbfargko" string and replace spaces whit commas for proper color formatting. See:



          enter image description here



          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered yesterday









          Oto KalábOto Kaláb

          4,11231431




          4,11231431























              2














              In the layer properties, in the symbology tab, define the color by an expression (link to the QGIS doc) :



              color_rgb(
              array_get(string_to_array("rgbfargko", ' '), 0),
              array_get(string_to_array("rgbfargko", ' '), 1),
              array_get(string_to_array("rgbfargko", ' '), 2)
              )


              Explanation of the code :



              1- function string_to_array : transform the field data into an array by splitting at the white space character ;
              2- function array_get : get elements of the array, the first item has an index of 0 ;
              3- function color_rgb : with 3 arguments (R, G, B), this function return a QGIS color.



              EDIT
              The solution of @Ian Turton is more visual and simple !






              share|improve this answer






























                2














                In the layer properties, in the symbology tab, define the color by an expression (link to the QGIS doc) :



                color_rgb(
                array_get(string_to_array("rgbfargko", ' '), 0),
                array_get(string_to_array("rgbfargko", ' '), 1),
                array_get(string_to_array("rgbfargko", ' '), 2)
                )


                Explanation of the code :



                1- function string_to_array : transform the field data into an array by splitting at the white space character ;
                2- function array_get : get elements of the array, the first item has an index of 0 ;
                3- function color_rgb : with 3 arguments (R, G, B), this function return a QGIS color.



                EDIT
                The solution of @Ian Turton is more visual and simple !






                share|improve this answer




























                  2












                  2








                  2







                  In the layer properties, in the symbology tab, define the color by an expression (link to the QGIS doc) :



                  color_rgb(
                  array_get(string_to_array("rgbfargko", ' '), 0),
                  array_get(string_to_array("rgbfargko", ' '), 1),
                  array_get(string_to_array("rgbfargko", ' '), 2)
                  )


                  Explanation of the code :



                  1- function string_to_array : transform the field data into an array by splitting at the white space character ;
                  2- function array_get : get elements of the array, the first item has an index of 0 ;
                  3- function color_rgb : with 3 arguments (R, G, B), this function return a QGIS color.



                  EDIT
                  The solution of @Ian Turton is more visual and simple !






                  share|improve this answer















                  In the layer properties, in the symbology tab, define the color by an expression (link to the QGIS doc) :



                  color_rgb(
                  array_get(string_to_array("rgbfargko", ' '), 0),
                  array_get(string_to_array("rgbfargko", ' '), 1),
                  array_get(string_to_array("rgbfargko", ' '), 2)
                  )


                  Explanation of the code :



                  1- function string_to_array : transform the field data into an array by splitting at the white space character ;
                  2- function array_get : get elements of the array, the first item has an index of 0 ;
                  3- function color_rgb : with 3 arguments (R, G, B), this function return a QGIS color.



                  EDIT
                  The solution of @Ian Turton is more visual and simple !







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited yesterday

























                  answered yesterday









                  J. MonticoloJ. Monticolo

                  1,155217




                  1,155217






















                      Casairo is a new contributor. Be nice, and check out our Code of Conduct.










                      draft saved

                      draft discarded


















                      Casairo is a new contributor. Be nice, and check out our Code of Conduct.













                      Casairo is a new contributor. Be nice, and check out our Code of Conduct.












                      Casairo is a new contributor. Be nice, and check out our Code of Conduct.
















                      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%2f316218%2fassign-a-specific-color-to-vector-layer-based-on-rgb-codes-in-attribute-table%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 did Captain America manage to do this?

                      迪纳利

                      南乌拉尔铁路局