Developing your own styles

In QGIS, a style is a way of cartographic visualization that takes into account a layer's inpidual and thematic features. It encompasses basic characteristics of symbology, such as the color and presence of fill, outline parameters, the use of markers, scale-dependent rendering, layer transparency, interactions with other layers, and labels.

A well-chosen style greatly simplifies data perception and readability, so it is important to learn how to work with styles in order to be capable of representing your data in the best way. In this section, we will discuss vector and raster layers separately, as their stylization has some unique features.

Developing styles for vector layers

The Style menu from the Layer Properties dialog provides you with all the necessary tools to symbolize and style your data. To open it, double-click on a layer name in the Layers panel, or use the Properties right-click contextual shortcut, and select the Style section. You will see something similar to this:

The very first thing you should pay your attention to is the small Renderer drop-down type list in the top-left corner. It contains the following items:

  • Single Symbol: This is the simplest type that draws all the layer features with the same symbol.
  • Categorized: This defines data-driven categories and allows us to symbolize them inpidually.
  • Graduated: This defines the categories based on quantitative attributes, allowing us to rank features gradually.
  • Rule-based: This is the most flexible and advanced renderer type. It allows the user to define their own categories using multiple criteria and style them inpidually.
  • Point displacement: This renderer is useful when you are working with a point layer containing overlapping points that have similar coordinates or are located too close to each other. It is available only for single point layers, and will automatically shift the location of the markers so that all overlapping markers are visible.
  • Inverted polygons: These are used to style the area exterior to the polygon, and are available for polygon layers only.
  • Heatmap: This represents a point layer with a continuous surface according to the points' density, It is available for point layers only.

Depending on the renderer type selected, the Style menu section changes its view, and if you mistakenly select an inappropriate type (for example, the heat map renderer for a line layer), you will get the corresponding message.

After the renderer type is chosen, you can start adjusting the symbology with the Symbol selector dialog, whose accessibility depends on the renderer type selected. For example, for the Single symbol and the Inverted polygons renderer, this dialog is directly available from the Style section. For the Categorized and Graduated renderers, it is available from the Symbol Change button, which looks like this: Developing styles for vector layers.

Rule-based, Point displacement, and Heatmap renderers have their own specifications for symbology selection and adjustment, which will be covered in the following sections. Nevertheless, regardless of the renderer type selected (except the Heatmap renderer), you always have access to the Symbol selector dialog, which looks similar to what is shown in the following screenshot and consists of several sections:

In the top-left part of the window, you can see a symbol preview. Underneath the preview, there are symbol layers. By default, only one layer is used, but you can add more with the Add symbol layer button, Developing styles for vector layers, or remove unnecessary layers with the Remove symbol layer button, Developing styles for vector layers, which is active only if there are two or more layers available. With the Lock layer's color button, Developing styles for vector layers, the layer's color will be locked for changes, which prevents colors from being modified by a categorized or graduated renderer. Layers can be reordered with the Move up (Developing styles for vector layers) and Move down (Developing styles for vector layers) buttons, and if you are satisfied with the result, use the Save symbol button in the symbol library.

In the right-hand side of the dialog window, there are options available for the symbol layer selected. Among them, Symbol layer type is the most important. The list of available types depends on the layer geometry. For a polygon layer, you can select from the following list:

  • Centroid fill: Polygons are symbolized by a marker at the polygon's centroid, instead of rendering the entire area of the polygon. This is useful if you have a lot of small polygons that are better to visualize by a point than by a tiny polygon that is visible only after zooming in.
  • Gradient fill: Use a predefined gradient or create a custom gradient to fill the polygon.
  • Line pattern fill: Line patterns can be combined to create various hatching effects. These effects are useful when you want to use the same fill color underneath but want to highlight some differences between objects with hatching.
  • Point pattern fill: Regularly distributed points (or other symbols) can fill the polygon and create a pattern.
  • Raster image fill: Any raster image can be used to create a background-filling texture or pattern.
  • SVG fill: A scalable vector graphics .svg file (or a marker) can be used to create a filling texture or pattern.
  • Shapeburst fill: This shades the interior of a polygon, depending on the distance from the edge of the polygon, and creates amazing border buffering effects.
  • Simple fill: This the default type, and is characterized by fill color, pattern, and border.
  • Outline: marker line: A marker symbol is used as the outline.
  • Outline: Simple line: Only the polygon's outline is drawn and its properties defined by line color, width, and style.

For a point layer, you can choose from different marker types represented by Ellipse, letters or signs (Font marker), various markers (Simple marker), icons (SVG marker), or attribute field values (Vector Field marker).

For a line layer, the Simple and Marker line types are available. In the first case, the line is rendered as usual, and in the second, a regularly recurring marker symbol is used. Marker line can be used, for example, to show a line's direction (movement on a road, a river flow, and so on) with an arrow marker symbol.

Now that we have covered the basics, we will closely explore different rendering styles in the example of some layers from our database.

Styling a layer with the Single Symbol renderer

In this example, we will use the Brooklyn borough boundaries layer to outline the area of interest on the map. As you can see in the following screenshot, we use two symbol layers, both defined as Outline: Simple line, but with different Pen style patterns. Underneath, we place a lighter Solid line and cover it with a darker Dash Line pen style. Selecting contrast colors allows us to implement a border-like stripe effect.

Styling a layer with the Categorized renderer

Let's style the public schools layer to reflect the school type:

  1. After setting the renderer type to Categorized, select the column with the categories to be rendered under Column. The column is available from the drop-down list that contains all the layer attribute fields. As we want school types to be shown as categories, select the sch_type field to categorize the layer:
  2. Click on the Symbol Change button to adjust the layer symbology. In the Symbol selector window, set Symbol layer type to SVG marker and navigate to the training dataset catalog called svg. Select the school.svg file and adjust the symbol's Size value to 3 mm. Click on the OK button to come back to the main window:
  3. Click on the Classify button. The window with the Symbol, Value, and Legend columns will automatically be populated with the categories and their descriptions from the attribute field. The difference between Value and Legend is that values represent unique attributes, while the legend provides their descriptive characteristics. It's more obvious when values, for example, are some codes and the legend is supposed to explain their meaning. Also, values are not visible in the layer's legend, but their descriptions are. You can add or delete the categories, or manually edit the text of its elements (Value or Legend) by double-clicking on the item in the relevant column. For now, just click on OK to exit the Style dialog and take a look at the preliminary result.
  4. You will see that the symbols on the map canvas are too dense and overlapped, which makes the map cluttered. To enhance readability, we should relate the appearance of symbols with a scale, and there are two basic approaches to do this:
    • Activate Scale dependent visibility from the General tab of the Properties window, where you should enter values of Minimum (exclusive) and Maximum (inclusive) scales. For example, if you define the values, as shown in the following screenshot, the layer will become visible within a scale range of 1:49,999 (because the minimum value of 50000 is excluded) and more. This approach doesn't affect the symbol's size. It only regulates the scale range for its appearance while zooming in and out of the map canvas:
    • The other approach, which we will actually use, is more sophisticated because it makes the symbol size dependent on the scale. To apply it, open the Style dialog in the Properties window, and click on Styling a layer with the Categorized renderer, the SymbolChange button, to open the Symbol selector dialog, as shown. Activate the necessary symbol layer, change its Size units to Map unit, and enter 30. This means that the symbol size will be set 30 feet and changed according to the scale while zooming in or out. Click on the OK button to come back to the main window.
      Tip

      In this case, the scale range can be defined through the Adjust scaling range button (Styling a layer with the Categorized renderer), which opens a dialog window to define the minimum and maximum scale values.

  5. By default, all categories are assigned the same Symbol marker according to the SVG file selected, but you can modify it by double-clicking and adjusting the necessary properties (that is, Fill and Border) in the Symbol selector dialog. Also, right-clicking on any item brings up a contextual menu with the Copy, Paste, Change color, Change transparency, Change output unit, and Change size shortcuts for simplifying some common actions.

This screenshot shows what the screen may look like if you choose the Categorized renderer and adjust the settings as described previously:

After you've clicked on the OK button, the layer's style properties will be applied, and you can explore the layer visibility in the map canvas. In the case of map unit related symbol size, you will probably not be able to see markers while zooming out, but they will appear on larger scales, changing in size accordingly. Note that the symbols in the layer's legend on the Layers panel behave similarly, that is, become larger on larger scales and shrink on smaller scales. This helps you know whether the layer is visible on this scale, and if it is, helps you see the appearance of its markers.

Styling a layer with the Graduated renderer

The Graduated renderer type is useful when you want to grade features according to some quantitative attribute. In our sample dataset, we have the zipcodes layer, which contains data about population in the population field. We will use this layer and field to rank ZIP code boundaries according to the number of people living and demonstrate how graduated rendering works.

Tip

Instead of choosing an attribute field, you can click on the Expression dialog button Styling a layer with the Graduated renderer, beside it. It will be useful if you need to use some values that are not in the attribute table, but can be derived from the field values. For example, you can use the area/ 43560 expression to convert area in square feet into acres.

  1. Set the renderer type to Graduated and select the population field in the Column section.
  2. Define the number of classes you wish to show (normally, five to seven classes are recommended, otherwise it can be difficult to distinguish between them visually), and select a Color ramp.
    Tip

    You can use a predefined standard color ramp or select from the advanced options. To use them, select New color ramp from the bottom of the drop-down list. In the Color ramp type window, you will get access to the following options:

    • Gradient: This provides options to create and modify custom gradients.
    • Random: This creates a random color ramp according to various customizable options, such as Hue, Saturation, Value, and Classes.
    • ColorBrewer: Use predefined color palettes for maps designed for optimal clarity. This includes several color schemes for different kinds of data (sequential, pergent, and qualitative).
    • cpt-city: This provides access to dozens of color gradients for cartography, technical illustration, and design.
  3. Then, select an appropriate graduation mode, which is as follows:
    • Equal interval: The value range is pided into equal range classes according to the number of classes set (for example, values from 0 to 100 are pided into five classes of 20 units each).
    • Quantile (Equal Count): All of the data will be pided into the number of classes set, and ranges will be chosen in such a way that each class will contain the same number of items.
    • Natural Breaks (Jenks): This method groups values according to their similarity. So the values within a class have minimum variance, but feature values across classes vary significantly.
    • Standard Deviation: Classes are pided according to the standard deviation of the values, and this shows how the data differs from its mean value.
    • Pretty Breaks: This creates n+1 classes for the given range of values (that is, if 5 classes are set, the resulting amount will be 6), similar to Equal interval, but breaking points are selected so that the values are nicely rounded numbers (for example, multiples of 10 if using integers).

After you've clicked on the Classify button, the Symbol, Values, and Legend columns will be populated. Double-click on any of these to modify it. Right-clicking opens a contextual menu. It is strongly advisable to play around with the various classes and classification modes before deciding which is best for revealing the features of your data.

Styling a layer with the Rule-based renderer

The Rule-based renderer is the most flexible renderer because it allows you to pide data into your own complex categories and style them separately. We will explore the rule-based rendering capabilities in the example of the bike routes layer, which has a lot of attributes that are useful to visualize. For example, there are two fields that are of particular interest to visualize on map. The first one is allclasses, which contains the classification of the route types (for existing cycling facilities), based on the NYC Bicycle Master Plan classification. The types are as follows:

  • I: Greenway/multi-use path.
  • II: On-street striped bicycle lane.
  • III: On-street signed bicycle route.
  • 0: Planned, but not yet existing as a bike route.
  • L: Link. There is no facility present, but the element is suggested as a connection between portions of the bike network.
  • S: Stairs and pedestrian overpasses.

The second field is lanecount, which shows the number of lanes. Rules need to be used to combine these attributes into separate categories that show both the route type and lane count. Follow these steps to develop a Rule-based symbology for the layer:

  1. Navigate to Properties | Style and select the Rule-based renderer type from the drop-down list. To create a rule, click on the Add ruleStyling a layer with the Rule-based renderer button. The Rule properties dialog window will open.
  2. In the window, click on the ... button beside the Filter line. The Expression string builder window will open. This window consists of three sections:
    • The left section is Expression, with the row of operator buttons above it. You can either type the expression manually or double-click on field names, values, and functions to compose it.
    • The central section of the window is Functions. To expand any item, click on the + sign beside it and double-click to add it to the expression. We're mostly interested in the Field and Values items that contain all the available attribute field names. When you highlight any of them and click on the Load values buttons that are all unique or 10 samples, the list of values is returned. Again, you can either type a value in the expression manually or add it by double-clicking on it.
    • If you're lost, look at the right part of the window. It contains contextual help for the item highlighted in Functions.

    In our expression, we want to show greenways and multi-use paths that are in the I category. The "allclasses" = 'I' expression for this is shown in the following screenshot:

  3. After clicking on the OK button, you'll be in the Rule properties window again. First of all, test the consistency of the expression. You will get the message Filter returned 'some number' of feature(s). If the number of features is 0, it means that there are no features that satisfy the rule. Otherwise, you'll get a positive number that shows the number of features in the class.
  4. Then add a Label and, if necessary, Description to the class. If the Scale range toggle is activated, you can define the maximum-minimum scale range to visualize the class on a map. Class symbology is developed in the Symbol section of the window as shown:

    After clicking on the OK button, you will be back to the main Style window, where rules can be managed with the Add rule Styling a layer with the Rule-based renderer, Edit rule Styling a layer with the Rule-based renderer, or Remove rule Styling a layer with the Rule-based renderer buttons. Go ahead and add categories for the other classes available in this layer.

With the Refine current rules button, you can go further and develop multilevel hierarchy based on scales, categories, or ranges. For example, we can take allclasses as a major classification attribute and then pide it into subcategories by the number of lanes:

  1. Select category, navigate to Refine current rule | Add categories to rule, and select the lanecount field from the Column drop-down list. Click on the Classify button:

    Similarly, add subcategories to other rules.

  2. Now, we should check our rules to remove empty categories. Select all the available categories by holding down the Ctrl key, and click on the Count features button. Empty categories will be identified by the 0 count. Click on the Remove rule button Styling a layer with the Rule-based renderer to exclude them from the legend.
  3. As a result, your rule-based style may look like this:
  4. You can greatly improve the visualization of multilevel symbols by clicking on the Rendering order button and adjusting the symbol levels. In the opened Symbol Levels dialog window, you can define the order in which the symbol layers are rendered. The numbers in the cells decide in which rendering pass the layer will be drawn. The idea is that some symbol levels should have a lower rendering order and others should have higher rendering order. Lower levels will be covered by higher ones, allowing the user to create smooth conjunctions and preserve the symbology hierarchy. Set up the rendering order as shown in the following screenshot and explore the results:
Styling a layer with the Point displacement renderer

Some point layers (for example, the wifi public layer from the training dataset) contain points with the same or similar coordinates that are impossible to distinguish on the map because of their overlapping. In this case, Point displacement renderer can be of great use, as it locates overlapping points within an imaginary circle. It moves points to a small distance in such a way that they all become visible. Note that the renderer doesn't affect real point positions in the dataset, but visually changes placement to satisfy cartographic requirements. To be able to use this type of rendering, a layer should be a single point feature type.

To apply Point displacement renderer to the wifi public layer follow these steps:

  1. Choose the Center symbol marker around which the points will be displaced. By clicking on the symbol button, you get access to the conventional Symbols selector dialog. In the window, set Symbol layer type to SVG marker, navigate to the training dataset catalog called svg, and select the Wi-Fi-Logo.svg file. Set its size to 20 and select Map unit as the size measurements unit. After clicking on the OK button, you will be brought back to the main window.
  2. Go to Renderer | Single symbol for the points themselves. After clicking on the Rendering settings button below, you will be in the Symbol selector dialog. Again, set the symbol layer type to SVG marker, navigate to the training dataset catalog called svg, and select the wi-fi.svg file. Set its size to 30 and select Map unit as the size measurement unit. After clicking on OK, you will be taken back to the main window.
  3. The Rendering circles section defines the properties of the circles that appear on a map to group the points that have similar coordinates and are thus grouped around the common center. The following properties are included:
    • Circle pen width: This defines the outline width of the bordering circle
    • Circle color: This defines the outline color of the bordering circle
    • Circle radius modification: The bigger this value, the bigger the circle will be
    • Point distance tolerance: The bigger this value, the more the points to be snapped around the common center

    For now, we accept the default values and apply the settings. In the following screenshot, you can see what the result may look like in the case of several points that share similar coordinates and need to be grouped around a common center:

The Labels section contains some major labeling settings, for example, Label attribute, font, color, and so on. We temporarily omit this, as labeling will be covered later in the Adding labels section of this chapter.

Styling a layer with the Inverted polygons renderer

The Inverted polygons renderer styles the polygon outside its boundary and allows us to achieve remarkable cartographic effects. One of its common uses is for showing water bodies with the "fading out" blur effects on the map. For this purpose, Duplicate the NY borough boundaries layer with the right-click contextual shortcut, right-click to Rename it to water area, open the Style properties dialog, and select the Inverted polygons renderer.

Now, create a complex symbol that consists of two layers:

  1. The first Symbol layer type is set to Outline: simple line.
  2. The second one is Shapeburst fill.
    • In the Gradient colors section, we choose the Two color gradient from blue to white.
    • In Shading style, activate Shade to a set distance:. The bigger the value, the larger the shading effect will be.
    • Finally, adjust the Blur strength slider to a value of 10 to make blurring softer. Click on the OK button and enjoy the result!
Styling a layer with the Heatmap renderer

Heatmap is a relatively new renderer type. It was introduced in the QGIS 2.8. It represents a point as a continuous-density surface and allows us to apply cool styling effects. Note that in order to be able to apply this type of renderer, the layer and map canvas should be in the same coordinate reference system.

We will apply the renderer to the trees layer, which contains over 15000 points. These are hard to show on the map inpidually because of their high density:

  1. After selecting the Heatmap renderer type from the drop-down list, select a predefined color ramp for the layer called Greens. If you are not satisfied with the color ramp, you can modify it by clicking on the Edit button beside it, or create your own color ramp by choosing New color ramp from the very end of the list, and finally Invert the color ramp if there is a need.
  2. The Radius field determines the search area for density estimation. It basically represents how close points must be to each other to influence the heat map. The larger the radius, the smoother the surface; and the smaller the radius, the finer the details in the heat map. You can define the radius of a point in different units: Pixels, Millimeter, or Map unit. Remember that map units are scale dependent. Pixels and millimeters change regardless of the scale, but reflect zooming effects as well.
  3. Maximum value is usually set automatically and is responsible for the maximum density of points per area unit, but you can adjust it to your needs.
  4. Also, you can use a Weight points by numerical field just in case you want the layer to reflect some important information in addition to density. For example, if we have the relevant data, we can weigh schools by the number of students, or cafés by the number of visitors per month.
  5. The Rendering quality slider is used to adjust the smoothness of the surface. The higher the quality you choose, the slower the rendering process will be, while coarser surfaces are rendered faster.
Layer rendering

Whichever rendering type you choose, there are always the same Layer rendering options at the bottom of the Style dialog window. The first one is a general Layer transparency percentage slider. You can move it to adjust the layer transparency. Layer blending mode provides some special graphics effects for the layer you work with to interact with the bottom layer (or layers). By default, the Normal mode is set, which means that the underlying layer is hidden underneath without mixing of colors with covering layer. This is written as (a, b) = a, where a is the top layer and b is the bottom layer.

Example of the Normal blend mode applied to the overlapping layers

You can choose from among 12 different blending modes pided into four groups, as described in the following table:

Feature blending mode applies the same effects to the overlapping features within the layer. We advise you to give the different modes a try in order to understand how they work with different data types and styling options. Getting familiar with them allows you to create professional-looking maps with stunning cartographic design effects.

The preceding screenshot is an example of the hurricane evacuation zones layer combined with the underlying primary residential zoning layer through simple 50 percent transparency (on the left), versus the Multiply blending mode used without any transparency (on the right).

In the preceding screenshot, the noise point layer with simple marker fill opacity set to 20 percent; the Layer blending mode is Hard light and Feature blending mode is Dodge.

Developing styles for raster layers

Our dataset contains three raster layers: landcover 2010, height a.s.l., ft, and hillshade. All of these are remote sensing derivatives that are useful for representing land use and relief features. We will develop styles for them to represent the DEM as a continuous layer, and combine it with a hillshade to obtain some semi-3D cartographic effects. The landcover 2010 layer will be used to show how to work with the set of discrete classes.

First, let's style the landcover 2010 layer that contains several landcover classes. These are coded by integer values described in the metadata as follows:

  • 1: tree canopy
  • 2: grass/shrub
  • 3: bare earth
  • 4: water
  • 5: buildings
  • 6: roads
  • 7: other paved surfaces

Let's develop the styles by performing the following steps:

  1. Open the Style tab from the Properties dialog window (double-click on the layer in the legend, or select the Properties right-click contextual shortcut).
  2. Set Singleband pseudocolor as Render type. As our raster has only one band, it will be loaded automatically as Band 1 (Gray) in the Band drop-down list.
  3. As we work with discrete landcover classes, we go to Color interpolation | Discrete.
  4. Now we need to add our classes into the legend window. Use the Add values manually button, Developing styles for raster layers, to add classes.
  5. By default, all the classes are assigned the Value of 0, the same Color, and Custom color map entry instead of Label. You can change them by double-clicking on a correspondent item. When you're done, your Style section will look similar to what is shown in the following screenshot:
  6. For the height a.s.l., ft layer, in the Style section, select Render type as Singleband pseudocolor.
  7. The band will be set automatically, and in the case of smoothly changing values as in DEM, leave the default Linear option (under Color interpolation) unchangeable.
  8. Now, we need to select an appropriate color ramp for the thematic content of the layer. A predefined ramps drop-down list doesn't show you all of the available persity. To get this, select New color ramp. From the Color ramp type window drop-down list, select cpt-city. You will be shown all the available predefined color ramps, sorted into several thematic groups.
  9. Click on the Topography group, select the elevation ramp (or any other ramp you like), and click on the OK button.
  10. We will be asked to enter a name for new color ramp. Click on OK as we're satisfied with the existing one. Then, we'll be back to the main Style window.
  11. Navigate to Mode | Continuous, and QGIS will create classes after you click on the Classify button. The min / max values range within which these classes will be created is defined in the Load min/max values section with the following options, as shown in the following screenshot:
    • Cumulative count cut: By default, this is set to 2-98 percent of the data range and helps cut very low or very high data outliers. Choosing this type of data range setting, the initial image gains more contrast and better reflects differences in the data values.
    • Min / max: The entire data range is taken into account, but the resulting map may look dull.
    • Mean +/- standard deviation ×: Values within the given standard deviations (or deviations) define the data range.

To load values according to the specified data range mode, choose Actual (slower) in the Accuracy section option and click on the Load button. Depending on the dataset, it may take some time, and when you see that the Min and Max values below the color ramp and Mode are updated, click on the Classify button. In the window to the left, you will see classes and their ranges set up automatically within the defined data range. This is as per the color ramp chosen. It is important to understand that every value represents the maximum limit of the class, and the highest value is not the real maximum value of the dataset, but the cumulative maximum count. You can adjust values by double-clicking on them and typing integer values, and clarify the legend by entering ranges instead of single values. Look at the preceding screenshot to understand these explanations.

Finally, let's style the hillshade raster to reveal details and roughness of relief. Before starting, make sure that the layer is above height a.s.l., ft, and if not, drag it and place it properly. Hill-shading simulates how sunrays illuminate the terrain. Combining it with DEM is a very popular approach in cartographic visualization for implementing semi-3D effects and highlighting relief details. Conventionally, semi-transparent hill-shading is overlaid above the terrain layer to achieve this. As a result, the final terrain visualization loses color contrasts and becomes dull. To overcome this, we will first move the Global transparency slider to 50 percent in the Transparency section under Layer properties, and in the Style section, select Multiply from the Blending mode drop-down list. If you're not sure about what exactly has happened, try to apply Normal blending mode using Apply, and then go back to Multiply. The following screenshot shows the difference:

The preceding screenshot shows combined hillshade and DEM layers using simple 50 percent transparency (above) and the Multiply layer blending mode with 50 percent transparency (below).