- QGIS:Becoming a GIS Power User
- Anita Graser Ben Mearns Alex Mandel Víctor Olaya Ferrero Alexander Bruy
- 1778字
- 2021-07-09 19:32:32
Styling vector layers
When we load vector layers, QGIS renders them using a default style and a random color. Of course, we want to customize these styles to better reflect our data. In the following exercises, we will style point, line, and polygon layers, and you will also get accustomed to the most common vector styling options.
Regardless of the layer's geometry type, we always find a drop-down list with the available style options in the top-left corner of the Style dialog. The following style options are available for vector layers:
- Single Symbol: This is the simplest option. When we use a Single Symbol style, all points are displayed with the same symbol.
- Categorized: This is the style of choice if a layer contains points of different categories, for example, a layer that contains locations of different animal sightings.
- Graduated: This style is great if we want to visualize numerical values, for example, temperature measurements.
- Rule-based: This is the most advanced option. Rule-based styles are very flexible because they allow us to write multiple rules for one layer.
- Point displacement: This option is available only for point layers. These styles are useful if you need to visualize point layers with multiple points at the same coordinates, for example, students of a school living at the same address.
- Inverted polygons: This option is available for polygon layers only. By using this option, the defined symbology will be applied to the area outside the polygon borders instead of filling the area inside the polygon.
- Heatmap: This option is available only for point layers. It enables us to create a dynamic heatmap style.
- 2.5D: This option is available only for polygon layers. It enables us to create extruded polygons in 2.5 dimensions.
Creating point styles – an example of an airport style
Let's get started with a point layer! Load airport.shp
from your sample data. In the top-left corner of the Style dialog, below the drop-down list, we find the symbol preview. Below this, there is a list of symbol layers that shows us the different layers the symbol consists of. On the right-hand side, we find options for the symbol size and size units, color and transparency, as well as rotation. Finally, the bottom-right area contains a preview area with saved symbols.
Point layers are, by default, displayed using a simple circle symbol. We want to use a symbol of an airplane instead. To change the symbol, select the Simple marker entry in the symbol layers list on the left-hand side of the dialog. Notice how the right-hand side of the dialog changes. We can now see the options available for simple markers: Colors, Size, Rotation, Form, and so on. However, we are not looking for circles, stars, or square symbols—we want an airplane. That's why we need to change the Symbol layer type option from Simple marker to SVG marker. Many of the options are still similar, but at the bottom, we now find a selection of SVG images that we can choose from. Scroll through the list and pick the airplane symbol, as shown in the following screenshot:

Before we move on to styling lines, let's take a look at the other symbol layer types for points, which include the following:
- Simple marker: This includes geometric forms such as circles, stars, and squares
- Font marker: This provides access to your symbol fonts
- SVG marker: Each QGIS installation comes with a collection of default SVG symbols; add your own folders that contain SVG images by going to Settings | Options | System | SVG Paths
- Ellipse marker: This includes customizable ellipses, rectangles, crosses, and triangles
- Vector Field marker: This is a customizable vector-field visualization tool
- Geometry Generator: This enables us to manipulate geometries and even create completely new geometries using the built-in expression engine
Simple marker layers can have different geometric forms, sizes, outlines, and angles (orientation), as shown in the following screenshot, where we create a red square without an outline (using the No Pen option):

Font marker layers are useful for adding letters or other symbols from fonts that are installed on your computer. This screenshot, for example, shows how to add the yin-and-yang character from the Wingdings font:

Ellipse marker layers make it possible to draw different ellipses, rectangles, crosses, and triangles, where both the width and height can be controlled separately. This symbol layer type is especially useful when combined with data-defined overrides, which we will discuss later. The following screenshot shows how to create an ellipse that is 5 millimeters long, 2 millimeters high, and rotated by 45 degrees:

Creating line styles – an example of river or road styles
In this exercise, we create a river style for the majriver.shp
file in our sample data. The goal is to create a line style with two colors: a fill color for the center of the line and an outline color. This technique is very useful because it can also be used to create road styles.
To create such a style, we combine two simple lines. The default symbol is one simple line. Click on the green + symbol located below the symbol layers list in the bottom-left corner to add another simple line. The lower line will be our outline and the upper one will be the fill. Select the upper simple line and change the color to blue and the width to 0.3 millimeters. Next, select the lower simple line and change its color to gray and width to 0.6 millimeters, slightly wider than the other line. Check the preview and click on Apply to test how the style looks when applied to the river layer.
You will notice that the style doesn't look perfect yet. This is because each line feature is drawn separately, one after the other, and this leads to a rather disconnected appearance. Luckily, this is easy to fix; we only need to enable the so-called symbol levels. To do this, select the Line entry in the symbol layers list and tick the checkbox in the Symbol Levels dialog of the Advanced section (the button in the bottom-right corner of the style dialog), as shown in the following screenshot. Click on Apply to test the results.

Before we move on to styling polygons, let's take a look at the other symbol layer types for lines, which include the following:
- Simple line: This is a solid or dashed line
- Marker line: This line is made up of point markers located at line vertices or at regular intervals
- Geometry Generator: This enables us to manipulate geometries and even create completely new geometries using the built-in expression engine.
A common use case for Marker line symbol layers are train track symbols; they often feature repeating perpendicular lines, which are abstract representations of railway sleepers. The following screenshot shows how we can create a style like this by adding a marker line on top of two simple lines:

Another common use case for Marker line symbol layers is arrow symbols. The following screenshot shows how we can create a simple arrow by combining Simple line and Marker line. The key to creating an arrow symbol is to specify that Marker placement should be last vertex only. Then we only need to pick a suitable arrow head marker and the arrow symbol is ready.

Tip
Whenever we create a symbol that we might want to reuse in other maps, we can save it by clicking on the Save button under the symbol preview area. We can assign a name to the new symbol, and after we save it, it will be added to the saved symbols preview area on the right-hand side.
Creating polygon styles – an example of a landmass style
In this exercise, we will create a style for the alaska.shp
file. The goal is to create a simple fill with a blue halo. As in the previous river style example, we will combine two symbol layers to create this style: a Simple fill layer that defines the main fill color (white) with a thin border (in gray), and an additional Simple line outline layer for the (light blue) halo. The halo should have nice rounded corners. To achieve these, change the Join style option of the Simple line symbol layer to Round. Similar to the previous example, we again enable symbol levels; to prevent this landmass style from blocking out the background map, we select the Multiply blending mode, as shown in the following screenshot:

Before we move on, let's take a look at the other symbol layer types for polygons, which include the following:
- Simple fill: This defines the fill and outline colors as well as the basic fill styles
- Centroid fill: This allows us to put point markers at the centers of polygons
- Line/Point pattern fill: This supports user-defined line and point patterns with flexible spacing
- SVG fill: This fills the polygon using SVGs
- Gradient fill: This allows us to fill polygons with linear, radial, or conical gradients
- Shapeburst fill: This creates a gradient that starts at the polygon border and flows towards the center
- Outline: Simple line or Marker line: This makes it possible to outline areas using line styles
- Geometry Generator: This enables us to manipulate geometries and even create completely new geometries using the built-in expression engine.
A common use case for Point pattern fill symbol layers is topographic symbols for different vegetation types, which typically consist of a Simple fill layer and Point pattern fill, as shown in this screenshot:

When we design point pattern fills, we are, of course, not restricted to simple markers. We can use any other marker type. For example, the following screenshot shows how to create a polygon fill style with a Font marker pattern that shows repeating alien faces from the Webdings font:

As an alternative to simple fills with only one color, we can create Gradient fill symbol layers. Gradients can be defined by Two colors, as shown in the following screenshot, or by a Color ramp that can consist of many different colors. Usually, gradients run from the top to the bottom, but we can change this to, for example, make the gradient run from right to left by setting Angle to 270
degrees, as shown here:

The Shapeburst fill symbol layer type, also known as a "buffered" gradient fill, is often used to style water areas with a smooth gradient that flows from the polygon border inwards. The following screenshot shows a fixed-distance shading using the Shade to a set distance option. If we select Shade whole shape instead, the gradient will be drawn all the way from the polygon border to the center.

- Learning Chef
- Boost C++ Application Development Cookbook(Second Edition)
- Apache Hive Essentials
- Python Network Programming Cookbook(Second Edition)
- TypeScript實戰指南
- Scala謎題
- Flutter跨平臺開發入門與實戰
- ServiceNow:Building Powerful Workflows
- Orleans:構建高性能分布式Actor服務
- QPanda量子計算編程
- 超簡單:Photoshop+JavaScript+Python智能修圖與圖像自動化處理
- 從零開始學UI:概念解析、實戰提高、突破規則
- Mastering Unreal Engine 4.X
- 大話代碼架構:項目實戰版
- Modern R Programming Cookbook