Assign a specific color to vector layer based on RGB codes in attribute table
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?
qgis attribute-table visualisation vector-layer
New contributor
add a comment |
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?
qgis attribute-table visualisation vector-layer
New contributor
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
add a comment |
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?
qgis attribute-table visualisation vector-layer
New contributor
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?
qgis attribute-table visualisation vector-layer
qgis attribute-table visualisation vector-layer
New contributor
New contributor
edited yesterday
Ian Turton♦
49.9k547115
49.9k547115
New contributor
asked yesterday
CasairoCasairo
162
162
New contributor
New contributor
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
add a comment |
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
add a comment |
3 Answers
3
active
oldest
votes
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.
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.
You missed a closing bracket)
.
– ahmadhanb
22 hours ago
add a comment |
AS @J. Monticolo supposed, use Data defined expression in symbology properties.
For expression you can simply use:
replace("rgbfargko",' ',',')
Which takse "rgbfargko" string and replace spaces whit commas for proper color formatting. See:
add a comment |
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 !
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
});
}
});
Casairo is a new contributor. Be nice, and check out our Code of Conduct.
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%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
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.
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.
You missed a closing bracket)
.
– ahmadhanb
22 hours ago
add a comment |
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.
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.
You missed a closing bracket)
.
– ahmadhanb
22 hours ago
add a comment |
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.
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.
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.
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.
edited 15 hours ago
answered yesterday
Ian Turton♦Ian Turton
49.9k547115
49.9k547115
You missed a closing bracket)
.
– ahmadhanb
22 hours ago
add a comment |
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
add a comment |
AS @J. Monticolo supposed, use Data defined expression in symbology properties.
For expression you can simply use:
replace("rgbfargko",' ',',')
Which takse "rgbfargko" string and replace spaces whit commas for proper color formatting. See:
add a comment |
AS @J. Monticolo supposed, use Data defined expression in symbology properties.
For expression you can simply use:
replace("rgbfargko",' ',',')
Which takse "rgbfargko" string and replace spaces whit commas for proper color formatting. See:
add a comment |
AS @J. Monticolo supposed, use Data defined expression in symbology properties.
For expression you can simply use:
replace("rgbfargko",' ',',')
Which takse "rgbfargko" string and replace spaces whit commas for proper color formatting. See:
AS @J. Monticolo supposed, use Data defined expression in symbology properties.
For expression you can simply use:
replace("rgbfargko",' ',',')
Which takse "rgbfargko" string and replace spaces whit commas for proper color formatting. See:
answered yesterday
Oto KalábOto Kaláb
4,11231431
4,11231431
add a comment |
add a comment |
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 !
add a comment |
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 !
add a comment |
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 !
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 !
edited yesterday
answered yesterday
J. MonticoloJ. Monticolo
1,155217
1,155217
add a comment |
add a comment |
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.
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.
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%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
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
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