Basic Vector Styling (QGIS3)¶
353 / 5000
Tổng quan về nhiệm vụ¶
Chúng ta sử dụng một tệp CSV chứa vị trí của tất cả các nhà máy điện trên thế giới và tạo một hình ảnh trực quan cho thấy sự phân bố của các loại nhiên liệu tái tạo và không tái tạo được sử dụng trong các nhà máy điện này.
Các kĩ năng khác mà bạn sẽ được học¶
Sử dụng các biểu thức để nhóm nhiều giá trị thuộc tính vào một danh mục đơn
Lấy dữ liệu¶
World Resources Institute đã biên soạn một cơ sở dữ liệu toàn diện, mã nguồn mở về các nhà máy điện trên thế giới bao gồm hơn 30000 nhà máy. Tải The Global Power Plant Database từ cổng thông tin mở WRI Open Data Portal.
Natural Earth có nhiều dữ liệu vector toàn cầu. Tải 10m Physical Vectors - Land chứa các polygon vùng đất liền.
Để thuận tiện, bạn có thể tải xuống trực tiếp bản sao của các lớp trên từ bên dưới:
globalpowerplantdatabasev120.zip
Data Source [WRI] [NATURALEARTH]
Tiến trình¶
Giải nén cả hai tập dữ liệu vào một thư mục trên máy tính của bạn. Trong Bảng điều khiển trình duyệt QGIS, định vị thư mục mà bạn đã trích xuất dữ liệu. Mở rộng thư mục `` ne_10m_land '' và chọn lớp `` ne_10m_land.shp ''. Kéo lớp vào khung cửa sổ.
Bạn sẽ nhận được một lớp mới `` ne_10m_land '' được thêm vào bảng điều khiển: guildabel: Layers. Cơ sở dữ liệu nhà máy điện toàn cầu có dạng tệp CSV, vì vậy chúng tôi sẽ cần nhập nó vào. Nhấp vào nút: guildabel: Open Data Source Manager trên: guildabel:` Data Source Toolbar`. Bạn cũng có thể sử dụng: kbd: phím tắt Ctrl + L.
Trong cửa sổ: guildabel: Data Source Manager, chuyển sang tab: guildabel:` Delimited Text`. Nhấp vào nút: guildabel: ... bên cạnh: guildabel: Tên tệp và duyệt đến thư mục nơi bạn đã trích xuất tệp` globalpowerplantdatabasev120.zip ''. Chọn ` global_power_plant_database.csv ''. QGIS sẽ tự động phát hiện các trường phân tách và hình học. Để lại: guildabel: Geometry CRS thành giá trị mặc định là` EPSG: 4326 - WGS84 ''. Nhấp vào: Guildabel: `Thêm sau đó là: guildabel:` Đóng`.
A new layer
global_power_plant_database
will be added to the Layers panel and you will see the points representing the power plants in the canvas. Now we are ready to style both these layers. Click the Open the Layer Styling panel button at the top of the Layers panel.
The Layer Styling panel will open on the right. Select the
ne_10m_land
layer first. This will be our base layer so we can keep the styling minimalistic so it is not distracting. ClickSimple fill
and scroll down. Select a Fill color as per your liking. Click the drop-down next to Stroke color and selectTransparent Stroke
. This will set the outlines of the land polygons to be transparent. You will see the result of your selection applied immediately to the layer.
Next select the
global_power_plant_database
layer. Click onSimple marker
and scroll down. Pick a triangle marker.
Scroll up and select a Fill color of your liking. A useful cartographic technique is to choose a slightly darker version of the fill-color as the Stroke color. Rather than trying to pick that manually, QGIS provides an expression to control this more precisely. Click the Data defined override button and choose Edit.
Enter the following expression to set the color to be 30% darker shade than the fill color and click OK.
darker(@symbol_color, 130)![]()
Ghi chú
Note that this expression is independent of the fill color you have chosen. You will see that this is immensely useful in the following steps where it automatically sets the border color based on the fill color provided.
You will notice that the Data defined override button next to Stroke color has turned yellow - indicating than this property is controlled by an override. A single symbol rendering of the power plants layer is not very useful. It doesn't convey much information except the locations of the power plants. Let's use a different renderer to make it more useful. Click the Symbology drop-down and select
Categorized
renderer.
The
global_power_plant_database
layer contains an attribute indicating the primary fuel used in each power plant. We can create a style where each unique fuel type is shown in a different color. Selectprimary_fuel
as the Column. Click Classify. You will multiple categories appear and the map rendering change accordingly.
While a Categorized view is useful, this layer contains too-many categories for one to meaningfully interpret the map. A better approach would be to group certain type of fuel categories and reduce the number of classes. Let's try to create 3 categories - Renewable fuel, Non-renewable fuel and Other. Select
Rule-based
renderer. Select all but one rules by holding the Ctrl key and clicking on each row. Once selected, click the Remove selected rules button to delete them.
Select the remaining rule and click Edit current rule.
Enter
Renewable fuel
as the Label. Click the Expression button next to Filter.
In the Expression String Builder dialog, enter the following expression and click OK. Here we are grouping multiple renewable energy categories into a single category.
"primary_fuel" IN ('Biomass', 'Geothermal', 'Hydro', 'Solar', 'Wind', 'Storage', 'Wave and Tidal')![]()
Ghi chú
The types of fuel chosen for renewable vs. non-renewable categories is based on Wikipedia. There are alternate definitions and classifications that may not match what is chosen here.
Scroll down and click Simple marker. Choose an appropriate Fill color. Once done, click the Back button.
You will see a single rule being applied to the layer for the Renewable fuel category. Right-click the row and choose Copy. Right-click again and choose Paste.
A copy of the existing rule will be added. Select the newly added row and click Edit current rule.
Enter
Non-renewable fuel
as the Label. Click the Expression button next to Filter.
In the Expression String Builder dialog, enter the following expression and click OK.
"primary_fuel" IN ('Coal', 'Gas', 'Nuclear', 'Oil', 'Petcoke')![]()
Scroll down and click Simple marker. Choose an appropriate Fill color. Once done, click the Back button.
Repeat the Copy/Paste process to add a third rule. Select it and click Edit current rule.
Enter
Other
as the Label. Choose Else - Catch all for other features instead of a Filter. This will ensure that any category missed in the previous 2 rules, will be styled by this rule. Scroll down and click Simple marker. Choose an appropriate Fill color. Once done, click the Back button.
The re-categorization is complete now. You will see a much cleaner view that shows the distribution of renewable vs. non-renewable fuel sources used by power plants and their distribution across countries. This however doesn't give a complete picture. We can add another variable to the styling. Rather than displaying all markers with uniform size, we can show the sizes proportional to the power generation capacity of each plant. This cartography technique is called Multivariate mapping. Right-click the
Renewable fuel
rule and select Change Size.
Click the Data defined override button next to Size. Select Edit.
As the power generation capacity varies a lot among our dataset, an effective way to get a a small range for size is using the
log10
function. You can experiment with different expressions to arrive at what works best for your preferred visualization. Enter the following expression and click OK.
log10("capacity_mw") + 1![]()
Repeat the same process for other rules.
Once satisfied, you can close the Layer Styling panel.
Looking at our final visualization, you can immediately see the patterns in the dataset. For example, over Europe there are more power plants that use renewable energy source, but they are lower capacity than the plants that use non-renewable energy source.
If you want to report any issues with this tutorial, please comment below. (requires GitHub account)