QGIS Basic Skills|5 Advanced QGIS Layers (2)-Connection Attribute Table

There is a popular saying in GIS: 80% of the information about human activities is related to geographic location. However, a large part of the data we get does not have geographical geometry, but a table composed of text and numbers. For example, the statistical yearbook issued by the Bureau of Statistics every year. How to locate these tables on the map and use the table data for spatial visualization analysis is the basic skill that GISer needs to master.

This article uses the provincial administrative divisions of the country as the geospatial base map and the statistical yearbook as the source of the attribute table. From the four aspects of data preprocessing, table connection, attribute table use, and table persistence, it demonstrates the combination of spatial data and pure attribute data. The process of analysis.        

 

01 Obtain demo data

 

• The 2015 provincial administrative division of the country comes from the Resource and Environmental Science and Data Center. This layer is free and public data. Enter the URL: http://www.resdc.cn/Default.aspx, and you can download it for free after registration.

• The statistical yearbook is from the official website of the National Bureau of Statistics at http://www.stats.gov.cn/ and can be downloaded without registration.

For your convenience, the above data has been packaged and uploaded to the network disk. The connection is as follows:

Link: https://pan.baidu.com/s/18vKpBMjOGfT9nHcNo31bFw Extraction code: hkyi

 

02 pretreatment

 

Open the downloaded statistical yearbook data, and this article selects "the urban and rural composition of the population by region and the birth rate, death rate, and natural growth rate" as an example to demonstrate the operation. It can be seen that the spreadsheet is not suitable for direct import into QGIS. Before the spatial data is linked, the data needs to be preprocessed.

 

 

  • Handling multiple headers

 

The header of a statistical yearbook is generally composed of a title and an indicator name. The indicator name may contain multiple levels and needs to be merged layer by layer to get the complete column name of a certain column of data. This complex header style is commonly known as multiple headers. For example, the indicator name in the third column in the above figure should be: urban population; the indicator name in the fourth column is: urban population proportion (%). In order to facilitate computer processing, the complex index names and data column names are generally compared in data collation, and distributed with the content in the form of metadata.

 

The processing steps adopted in this article are: delete the table title, replace the Chinese indicator name with English, and retain the correspondence between the Chinese and English indicator names. The processing results are as follows:

 

 

  • Delete national data and blank lines

 

The "national" or "total" rows in the table are not at the same administrative level as other data and should be deleted. Blank lines added for reading convenience should also be removed.

 

  • Handling spaces in province names

 

In order to improve reading comfort and the aesthetics of paper publications in the statistical yearbook, spaces are added to the province names to achieve alignment effects. Because the space is also the content of the string for the computer, when the string is matched, the space often causes the matching to fail. Therefore, the space in the province name should be deleted in advance.

 

 

  •  Preprocessed data

 

 03 

 Open data

 

Start QGIS and click the [Open Data Source Manager] button on the [Data Source Manager] toolbar.

 

 

Switch to the [Vector] tab, select the downloaded provincial administrative division shape file, and click the [Add] button to open the layer. You can see that the provincial division layer "CN-sheng-A" has been added to the map window.

 

 

Right-click "CN-sheng-A" in the [Layer] panel, and select [Open Attribute Table] from the pop-up menu. Observe the attribute table of province-level divisions, including a total of 6 fields, among which the "SHENG" field is the first 2 digits of the administrative division code, and the "name" field is the province name. The data quality of the division code and name should be carefully checked, because these two attributes are usually used as the connection field in the data table connection operation.

 

 

Similarly, click the [Open Data Source Manager] button, switch to the [Separated Text File] tab, browse to the compiled statistical yearbook table, set the layer name to "POP2015", select "Comma" as the separator, and [Geometry Graphic Definition] Select "No Geometry (Attribute Table)", click the [Add] button to add the statistical yearbook to the [Layer] panel.

 

 

Right-click the pure attribute table "POP2015" layer, open the attribute table, and confirm that the opened data is correct.

 

 

04 Connection attribute table

 

The connection attribute table can be set through the [Connection] tab in the layer properties, or it can be completed using the processing tool [Connect Attributes by Field Value]. This article demonstrates the second method, which is to use the [Connect Attributes by Field Value] processing tool to realize the attribute table connection.

 

Click the menu [Processing] -> [Toolbox] to open the processing toolbox panel.

 

 

Enter "join" in the search bar of [Processing Toolbox], find [Vector General] -> [Connect Attributes by Field Value], and double-click to run the tool.

 

 

In the [Connect Properties by Field Value] dialog box, set the first input layer to "CN-sheng-A", which is a provincial administrative division layer with geometric figures, and set the connection field to "name". The second input layer is set to "POP2015", that is, the statistical yearbook pure attribute table layer, and the connection field is set to "name". Keep other parameters as default, click the [Run] button to connect to the attribute table.

 

Note that the connection field names of the first layer and the second layer need not be exactly the same, only the corresponding fields of the two layers can match.

 

 

Observing the output of the algorithm, 31 elements are correctly connected, which is the same as the number of provincial administrative division elements. The 4430 unmatched elements are islands far away from the mainland, and their "name" field is NULL, so the match fails.

 

 

Close the [Connect Attributes by Field Value] dialog box and return to the main QGIS window. You can see the newly added "Connected Layer" in the [Layer] panel. Right-click the layer to open the attribute table and make sure that the statistical yearbook fields It is correctly appended to the original attribute table of provincial administrative divisions.

 

 

 05 Visualization

 

After the statistical yearbook is connected with the administrative division layer, the yearbook data can be visualized on the map.

 

Click the [Open Layer Style] button in the [Layer] panel to open the Layer Style panel on the right.

 

 

Click [Layer Style] panel renderer drop-down box, select "Progressive" rendering. "Progressive" rendering uses different colors to express the value of the selected attribute field. It is usually used to express the numeric fields in a graded manner. Different colors are assigned with the size of the attribute value.

 

 

Since no fields are set for rendering, the map window is temporarily blank. Click the [Value] drop-down box, select the "Total_population" (total population at the end of the year) field, click the [Classification] button below, and a default thematic map will be displayed in the map window.

 

 

The default color is white -> red gradual, and the administrative divisions in the smallest interval are rendered as white, which blends with the map background color, and the effect is not good.

 

 

The map effect can be changed by setting the color progressive parameters. Click the drop-down box of [Color Gradient] and select [All Color Gradients] -> [RdYlGn] in turn.

 

 

Click [Color Gradient] again and select [Reverse Color Gradient] to invert the color band. Use green to render areas with small values ​​and red to render areas with large values.

 

 

Set the stroke of the symbol to be transparent, and finally get the following effect: the red dots represent the provinces with a large population at the end of the year, and the green dots represent the provinces with a small population at the end of the year.

 

 

 

 06 Save

 

In the [Layer] panel, the icon on the right of "Connected Layer" indicates that this layer is a temporary sketch layer and will be discarded when the project is closed. If you need to preserve the content of the layer, right-click the layer and select [Permanent...] from the pop-up menu to save the layer.

 

 

In the pop-up [Save Sketch Layer] dialog box, select the file format as "GeoPackage", set the file storage path and name, keep other parameters as default, and click [OK] to save the temporary layer to the hard disk.

 

 

In addition to linking the statistical yearbook data with the attribute table association, as long as there are matching fields in the spatial data and the attribute data, the association between the two can be realized.

 

Attribute data is an effective supplement to spatial data. However, the production process of the two types of data is not uniform, and even the data sources are different. As a result, the collected data is often separated from spatial data and attribute data. The tool [Connect Attribute Table by Field Value] in QGIS can realize the association of attribute data with spatial data, thus analyzing pure attribute data tables like operating a layer, creating conditions for the spatial visualization of attribute data.

 

- This chapter ends here -

 

[ --Recommended in the past-- ]

4 QGIS 3.x Advanced Layers (1) Create and Edit Layers

Serialization | 3 Picture check attributes, attribute check pictures

Serial | 2 layer basic operation

Serial | 1 Download and installation of QGIS


 

Copyright Notice

 

This article welcomes reprinting, please indicate the source when reprinting.

 

Guess you like

Origin blog.csdn.net/QGISClass/article/details/108689954