1

I work with geologists who are trying to figure out how to use Qgis to batch apply colour values to coordinates so that we can visually see differences or patterns.

From the attached photo of soil samples I've created an Excel file containing all the sample numbers and their corresponding average RGB colour (using the Photoshop color picker). The geologist has all the samples and coordinates in Qgis but only knows how to manually apply an colour value to each sample point which will take foreverrrr.

Is there a way to do this automatically so that we can see a grid of slightly varying soil colours?

(Just as an example, and I hope this doesn't confuse the question, but it occurred to me that a pixel level view of a(ny) raster image represents essentially the same kind of effect we are looking for... except each pixel would be a real life soil sample colour, and the location would be the coordinates in Qgis where that sample/colour came from. It doesn't have to be colour-up-against-colour like my example, but hopefully that helps illustrate the idea)

soil samples

example of each slightly varying colour plotted according to actual sample location.

edit: I have tried doing this with an expression as advised by user PolyGeo but am getting a NULL error in the expression dialog after following these steps: First we go to Layer Properties > Style Tab > Category ... then open the Expression Dialog > select Color dropdown > select color_rgb () option then input the variables into the brackets using the picker on the corresponding column labels Red, Green, and Blue. The resulting expression is color_rgb("Red", "Green", "Blue"). At the bottom of the dialog it says 'Exit Preview Error: NULL' This seems simple enough but we are clearly not doing something correctly.

1

If you have for each sample the RGB values in separate fields then it is easy using a data-defined override and the function "color_rgb("R column", "G column", "B column"). There is a good description of what you need to do at: Assign a specific color to vector layer based on RGB codes in attribute table

and at Using field-to-RGB mapping for symbology in QGIS?

Edit: If you are getting this data from excel or a similar source then perhaps there is either a column not being recognized as numeric or one containing a missing value or a text entry. I can reproduce your error with both the last 2 conditions.

| improve this answer | |
  • I tried this and commented with results to the original question, by chance do you have any ideas on that NULL error? – user3138173 Oct 29 '19 at 17:03
  • @user3138173 perhaps you can make available a file that generates this error (with suitable changes to anything that shouldn't be in the public domain). Then someone may be able to test for you and advise the issue. – Leigh Bettenay Nov 4 '19 at 1:04
-1

I think it will be possible if you clarify a bit what you are wanting. Do you want to apply the colour based on attributes you supply for each sample (for example from measured soil colour), or on coordinate values? If the former, then please indicate the form in which data are supplied- for example it might be in 3 separate fields for R, G and B, or in some string defining this. if the latter, then you have only 2 variables to define 3 colours.

| improve this answer | |
  • The colour needs to be overlaid on the map we have where the physical samples were taken from so that we can see patterns visually.... so, the colour from sample 'A' should be mapped to the coordinate where sample 'A' was taken. The average colour values for each soil sample was taken from the photo using Photoshop. Each row in the Excel file contains the soil sample number, its coordinates, the colour as HEX, RGB, and also split in to R, G, and B. – user3138173 Oct 26 '19 at 23:34
  • 2
    This answer should be a comment, and @user3138173 the comment response should be an edit to the question – nmtoken Oct 27 '19 at 8:57
  • @nmtoken point taken. Perhaps one of the moderators can amend this. – Leigh Bettenay Oct 27 '19 at 22:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.