5

I am trying to figure out how to do a styling of features on a mapi qgis, that is a sort of hybrid between the categorized and graduated styling.

I am doing a map of road trees in a city, and each tree is tagged with the species of the tree. There are about 40 different species among the 17000 trees in the attribute table.

What I would like to do is, instead of doing a simple color-coded categorized map, i would like to style the trees so that the least common species in the attribute table is the lightest in color, and the most popular species is the darkest in color.

Is this achievable?

2 Answers 2

5

I think it is achievable but will require a few steps.

  1. Here is an example layer:

    Trees


  1. Count the number of trees per species using the GroupStats plugin which can be downloaded from:

    Plugins > Manage and Install Plugins...

    Once installed, run it with the parameters shown in the image:

    GroupStats plugin

    Then save the results by going to Data > Save all to CSV file. Feel free to edit the csv file to add a column name to the count values (I just named it "Count").


  1. Add the csv file into QGIS using Layer > Add Layer > Add Delimited Text Layer as a table (i.e. no geometry), note that the plugin uses semi-colons as delimiters:

    Add csv file


  1. Join the shapefile with the loaded csv file:

    Join layers

    Your shapefile should now contain the "Count" column:

    Attribute table


  1. Now you can use the Categorized style and choose the "Count" column:

    Categorized style


6 (Optional). If you want to use the Graduated style, you will need to create a new integer field and copy the values from the "Count" column using the Field Calculator. Reason for this is (atleast for me), QGIS reads the "Count" from the csv as a string field, and the Gradiated style only accepts integer-type fields. Once the field is created with the values, you can un-join the csv file.

4
  • 1
    Thank you very much for your thorough step-by-step guide!
    – alxvo
    Commented May 23, 2016 at 11:50
  • @alxvo - Most welcome but I only just posted it 2 minutes before you accepted! You should test it to see if it works first =)
    – Joseph
    Commented May 23, 2016 at 11:51
  • 1
    Haha, you're absolutely right, that was premature of me -- however I have know managed to go through your guide with my dataset, and it worked perfectly! Thanks again.
    – alxvo
    Commented May 23, 2016 at 12:17
  • @alxvo - Awesome, glad you got it working :)
    – Joseph
    Commented May 23, 2016 at 12:17
1

A faster way would be to dissolve by tree species, then using the field calculator:

num_points($geometry)

This will then count all the points within each multipart feature

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.