In part two of these tutorial series, we will style more of our layers. While doing this we will start using more advanced symbology. In addition, we will look at filtering our data so as only to show the specific data we are interested in.
Types of railroads
- Let’s change the styling of the TRAMMETRO_LINES layer again. Make sure the layer is selected in the layers list. Right, click the layer in the layers list, and select Properties. Finally, press Symbology in the menu to the left.
- Now, instead of selecting a style for all features in the layer, we want different colours for the different unique values in the layer. Find the drop-down on the top of the window, and instead of Single symbol, select Categorized.
- Now we need to select which field (column) get used to symbolize on. Click the drop-down menu next to Column and select Modaliteit. As you might remember from before, this field relates to if the feature belongs to the tram or metro rail network.
- You will see that the information gets updated and QGIS assigns a different
colour to all unique values in the selected field. While you could assign a colour ramp to decide which colours the unique values get, I recommend to just simply manually pick colours since there are only two unique values. Similar to before, double-click each category’s symbol in the list, and change the colour to something you like (in my case: blue for metro, red for tram). Finally, change the line Width to 1 pt. to make the lines more clear on the map.
Your symbology window should now look like this:
- Your map should look similar to this:
We have 4 other layers looking forward to being symbolized, so let’s get moving. This time I will not go into as many details, as the workflow will be very similar as before.
- Toggle the visibility of the TRAMMETRO_STATIONS layer. Make sure it is listed above the layer we worked on before. If it is not, the station layer will be rendered underneath the railroads and you won’t be able to see the points representing stations. To change the order click, hold and drag the station layer name in the layers list above the TRAMMETRO_LINES layer.
- Check the attribute table of the stations’ layer. Right-click the layer in the layers list and select Open Attributes Table. You will find that the field we are interested in is, once again, called Modaliteit.
- Now, open the Symbology menu under Layer Properties, by right-clicking the layer in the layer list
- As before, select Categorized in the drop-down on the symbology window. Select Modaliteit as column name, and assign colours and sizes to the two different values. I would recommend using the same colours as the respective railroad colours and upping the size slightly (I chose a size of 3) to make the stations more clear on the map. Your map should now look like this:
- Now let’s look at the PARKS layer. Go ahead and activate it by clicking the checkbox to the left of its name in the layers list. You will see polygons pop up all over the map, representing parks. If you want the map to cover all the features in a layer, you can always right-click the layer in the contents pane and select Zoom to layer.
- While you might be tempted to style the parks with a green single symbol symbology and be done with it, let’s try something more fun. If we take a look at the attribute table we can see that there are a certain number of fields that we might be able to use for our symbology.
Similar to stations, we could use the categorized symbology, to create a more meaningful visualization. There are different options here. These include a field (BBQ) that indicates whether barbecuing is allowed, and Stadsdeel, which indicates in which district of the city the park lies. But both of these are not very meaningful in our analysis. But there is another field (Oppervlakt), which indicates the size of the park. This could be used and is actually relevant to our analysis to find an office located close to a park.
- Go ahead and select the Parks layer and open the Symbology menu on the layer properties window. Now, the option we are looking for is Graduated. Categorized will not work since there are so many unique park area values. Instead, we want to divide the areas into different groups. Graduated is perfect for this.
If you try selecting graduated and try to apply this symbology type to Oppervlakt, however, this field does not show up in the list. Why is this? When we inspected the attribute table the field certainly looked like it contained numbers. The problem is actually that the field type is Text. This needs to be a numeric type for the symbologies we are thinking about using since text value cannot be used for any calculations.
There is more than one way of doing this, but a common method is to create a new field with a numeric type, and copying the data from the Oppervlakt column. This is not as complicated as it sounds but requires a few steps.
- First, we need to create a new field of type decimal, which can hold numeric values without fractional values within a specific range. This field will include the same values as Oppervlakt does now, but just in a numeric format instead of text. This will allow us to use the field in calculations and more types of symbology. Open the attribute table of Parks. Above the attribute table, you will find the Field Calculator button.
- Press this button to open the field calculator. Here you can create a new field, with a certain field name, field type, and expression. For the field mame write something you like. I picked Area, although it should probably be something Dutch to stay consistent (sorry!). For field type pick Decimal number (real).
- Finally, write to_real( “Oppervlakt” ) in the expression text area. You can either write this, copy it from here, or fill in the values by finding to_real under the Conversion drop-down in the search area to the right of the text area, followed by clicking Oppervlakt under the Fields and values dropdown.Your field calculator window should now look like this:
Press OK. Notice the new field you just created in the attribute table. That was quick and very easy. If you have been following along with my ArcGIS Pro tutorial as well, you might have noticed how much quicker this went!
- We are now ready to apply the graduated symbology. Open the symbology window for the parks layer, and select Graduated as the symbology type. Notice that the new field Area now shows up in the column drop-down.
- Change the color ramp to Greens. Make sure you press the drop-down arrow to do this, instead of pressing the colored field.
- For Mode, select Natural Breaks (Jenks). The details of this are not important, but just know that this mode makes the quantities more evenly spread out between the different size classes. Your symbology window should look like this:
- Finally, press Classify in the bottom left of the window, and OK.
- Your map should now look like this:
Shortcut: I really wanted to show you how to create new fields with the field calculator. But a much quicker way to do this is by clicking the expression dialog button next to the column name drop-down in the symbology window. You can then write to_real( Oppervlakt) as the expression. This saves you from creating a new field!
- Finally, the quick thinker has probably noticed we also have data on the park names in its attribute table. We can use this to add labels to the map. Go to the layer properties window by right-clicking the parks layer in the layer list.
- Click Labels on the menu to the left.
- There is only one change we have to make. Next to Label with select the Naam field. Your labeling screen should now look like this:
Press Ok. The end result should look similar to this:
You might find this a little bit cluttered. Try figuring out how to make the labeling dependant on the map scale or park size! 🙂
The original idea was to be done with all label symbology in part 2 of this series, but this part grew out of proportions, so we will cover the final two layers in the next article, along with some other new stuff, such as layer subsets.