I have a LineString river shapefile. Using Categorized symbology, its features are classified by "Basin_ID" and then coloured using the random colours function.

I also have a polygon lakes shapefile which has the same attribute, Basin_ID. I achieved this by using the Join by Location process, so that lakes have the same Basin_IDs as the rivers they overlap.

I now want the colour of the lakes in the shapefile to be the same colour as rivers which share the same Basin_ID.

E.g there is a lake with Basin_ID = 4, then it should be coloured the same colour as the rivers which have the Basin_ID = 4.

How do I achieve this?

I cannot simply copy and paste the layer style, or save the style and then load it, as the two vectors are different types of shapefile (error message: Cannot apply style with symbology to layer with a different geometry type).

Using QGIS 3.22.6

  • If you are using Categorized symbols you should be able to select the color you want by the value in the field. Is that what you did for the river layer?
    – Cary H
    Commented May 26, 2022 at 15:30
  • There are thousands of features in both layers, so for the river layer I used random colours and then shuffled those random colours multiple times until I liked the look of the map. Thus it would be a miracle to use the same approach for the lakes layer and achieve the same colours for each corresponding feature.
    – Jude
    Commented May 26, 2022 at 15:53
  • You could take the randomness out by selecting a field that would be Unique to the color that you want to use. You could even add a field in the layer with the color name like "green" and then assign a color to that value in the field.
    – Cary H
    Commented May 26, 2022 at 20:34
  • Check this post: gis.stackexchange.com/questions/268877/…
    – geofausto
    Commented Jul 1, 2022 at 16:00

2 Answers 2


A short example:
I created a field named "Text" for the layer "Vertices" and put a bunch of numbers in it. I could have put the words for the colors I wanted to use. I then selected the Categorized Symbology and picked the Value "Text" from the list of fields in the layer.

When you Classify the group it will be a random color ramp. Then you can change the color of the "Value" that you want.

Below I changed all of the dots with the value "33" to a brown.

If you do add a field just for color you could just name the field "color" and put values like green, pink, red in there. That would make it easy to remember.

From your data:

Can you explain the 2 fields that should be linked between the rivers and lakes?

['fid', 'FID_ca_str', 'SUB_BAS', 'MAJ_BAS', 'MAJ_NAME', 'SUB_NAME', 'SUBBAS_ID', 'TOBAS_ID', 'Strahler', 'A_Strahler', 'RASTERVA_2', 'RASTERVA_1', 'path', 'BASIN_ID', 'AREA_SQKM', 'layer', 'path_2', 'color']

enter image description here

Categorized by value in Text Field

  • Thank you - although I'm afraid I didn't understand how I'd use this method to apply dozens of different colours to thousands of features without it being very manual. (the map is coloured by drainage basins, so the user needn't be able to register which colour is which on a legend, only that they are unique from their neighbours. I have uploaded the two shapefiles here we.tl/t-s8WBhgjRVN
    – Jude
    Commented May 27, 2022 at 11:59
  • Looks good. Your fields are ['fid', 'FID_ca_str', 'SUB_BAS', 'MAJ_BAS', 'MAJ_NAME', 'SUB_NAME', 'SUBBAS_ID', 'TOBAS_ID', 'Strahler', 'A_Strahler', 'RASTERVA_2', 'RASTERVA_1', 'path', 'BASIN_ID', 'AREA_SQKM', 'layer', 'path_2', 'color']. Do the lakes and rivers share the same BASIN_ID ? Example a lake that has BASIN_ID "121039" will be green and the River with BASIN_ID "121039" will also be green?
    – Cary H
    Commented May 27, 2022 at 13:05
  • The river layer has far many more and different BASIN_ID values than your lakes layer. It may be two other fields that should be linked.
    – Cary H
    Commented May 27, 2022 at 13:34

Thanks to all the replies. I managed to solve this the way that made sense to me.

The field that both the lake (polygons) and rivers (lines) layers had in common is BASIN_ID. Let's say there were 100,000 unique BASIN_IDs.

In Excel, I titled cell A1 as BASIN_ID. I then filled column A2 to A100001 with the numbers 1 to 100,000. In column B, I used the RANDBETWEEN function to assign each BASIN_ID a random number between 1 and 100,000. I could have just as easily done a smaller range. I titled this column "Colour" and saved the file as a CSV.

In QGIS, I imported the CSV as a non-geographical delimited file. I then joined the CSV to both of the shapefiles, one at a time, using BASIN_ID = BASIN_ID.

I could then go to each layer's symbology, set it to categorised, and set the value for categorisation as the Colour field. This field is now a random number but is the same random number for each BASIN_ID in both the lakes and rivers layers.

The final step is to replace the "Random Colours" palette as this wouldn't allow me to ensure the same colour for each classification. It's quite simple, create a new colour ramp that contains pretty much the full spectrum of the rainbow in equal proportion, and use this for the classification colouring.

I like this solution as I can use the same CSV file again and again on similar projects, and it takes very little time to set up.

Example of outcome

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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