Connect Shp and Excel attributes in Qgis to realize public budget space analysis of top 100 counties

foreword

        In the previous blog post, I downloaded the general public budget revenue data of the top 100 counties in the country in 2022 to the local. The original address of the blog: A method to quickly convert tables in the Web into Excel using Java . For general analysis that does not pay attention to the relationship between space and time, this is basically enough. However, if we observe and analyze the temporal and spatial distribution of these top 100 counties from a national perspective, it is very necessary to add a spatial dimension as the basis for spatial analysis.

        Under this background, this article focuses on explaining how to combine an ordinary two-dimensional table with spatial shp data for an excel sheet containing district and county information, combined with the corresponding spatial shp data, to realize the spatialization of two-dimensional data and give decision makers A distribution cognition on a geographical scale can better support economic services. This article will focus on how to use Qgis software to integrate the two, and finally draw a map based on the fusion results to get an intuitive result.

1. Data preparation

        Before the system integration, two pieces of data need to be prepared. The first is the excel file of the 2022 general public budget revenue list of the top 100 counties in the country downloaded from the Internet. The data list is as follows (Note: Among the top 100 counties in the country, the names of districts and counties are repeated incorrectly, so the use of city names for secondary filtering is not considered):

serial number column name example
1 county level Kunshan
2 Ministry Jiangsu
3 General public budget revenue (100 million yuan) 430.18

         The above is an excel two-dimensional table data. In order to carry out spatial analysis, a piece of spatial data is also required. Here, a national district and county data with the drawing approval number of 2019 China Map - Drawing Inspection Number GS(2019) 1822 is used. .

serial number

parameter name

value
1

name

County (equal area projection)

2 path F:\XXX\2019 China Map - Map Approval No. GS(2019) No. 1822\County (Equal Area Projection).shp
3

storage

ESRI Shapefile

4 coding

GBK

5

geometry

Polygon (MultiPolygon)

6

Coordinate Reference System (CRS)

Krasovsky_1940_Albers - Projection

7

unit

rice

8

number of elements

2,901

         Here you need to keep in mind the NAME field in the attribute table, because NAME will be used as the key field for data association later.

After simply symbolizing and labeling the above data, you can see the following map.

 2. Establishment of mapping relationship

        Through careful comparison and observation of Excel and Shp data, the two data are mapped and associated through the county-level areas in the excel table and the Name field in the Shp data. Its mathematical expression is as follows:

        Suppose R is an n-ary relationship, S is an m-ary relationship, A is an attribute of R, B is an attribute of S, and the value ranges of A and B have the same data type, θ∈{=, ≠, >, <, ≤, ≥}. The join operation of R and S is defined as:

Write picture description here

         Among them, r[A] represents the value of tuple r on attribute A, and s[B] represents the value of tuple s on attribute B. We call A and B connection properties. The link here should adopt the mode of equivalent link, that is, Inner Join. The statement translated into the database is roughly: Select A.* from TableA A join TableB B on A.xxx = B.xxx. The above theoretical knowledge is the theoretical basis for data to be able to establish connections.

3. Import Excel data into Qgis

        In order to facilitate the subsequent processing, we also put Excel into the Qgis platform. Since Excel does not have spatial coordinates, it cannot display spatial positions, only attribute information. In Qgis, you can open the attribute table of Excel to view the attribute table information.

         Here you can open the properties of excel, and the Field3 field has a corresponding relationship with the Name field in the Shp table. Keep this in mind, it will be used later.

4. Spatial data connection

         Based on the above results, we carry out the actual spatial data hooking. The operation steps are as follows:

        Step 1: Click the county (equal-area projection) with the mouse to open the property panel. As shown below:

         The second step, click the connect button, the following dialog box will pop up:

         Step 3: Click on the new connection, and associate and configure attributes in the new connection window. Here, the connection layer should be selected as the opened Excel layer, the connection field should be Field3, and the target field should be the Name field. When finished, click OK.

         After the above steps, the hooking of the attribute can be completed. After closing the window and clicking the Apply button, open the attribute table again to find out. The original attribute table has already attached a new attribute, which will be added later. The details are shown in the figure below:

         At this point, these attached fields are not the final fields. After the elements need to be exported, a new data will be automatically generated and the attributes will take effect. We modify the reference coordinate system to 4326.

 5. Data filtering of top 100 counties

        Careful friends found that after hooking, because we hooked the excel data into shp, excel only had 100 pieces of data, while there were 2901 pieces in shp, and 2801 pieces were not what we wanted, so we have to save this part Data is filtered from the repository. We opened the attribute table and found that the linked fields of the top 100 counties all have values, so we only need to filter out the data whose values ​​are not empty.

         We found that the property name of the mount is not very friendly, we can change it to English or other desired property names.

          Right-click the data, select Filter, and the following dialog box pops up to filter attributes in the query builder. According to the previous rules, the data that is not null for ggys is what we need, so the filter SQL we need to execute is

"ggys" is not null

         Click Test to verify the query results. By clicking, you can get the following results:

         This is the data of the top 100 counties in the country, and the obtained data can be exported to the outside as the basic data for the next step of mapping.

6. Cartography

        In order to better display the space, different general public budget revenues are used to distinguish the display, and the revenue information of different districts and counties can be visually seen from the setting of space and value range. Requires us to map against the value of public budget revenue. Specific steps are as follows:        

        The first step is to symbolize, click on the layer that needs to be symbolized, and select the classification method to symbolize.

         The second step is labeling. Spatial labeling of district and county information makes it more intuitive for readers.

         The final rendering (classified based on provinces) is as follows:

         In addition to classifying by province, it can also be classified and displayed according to different income types. Here is a progressive classification method:

 Summarize

        The above is the main content of this article. This article focuses on how to combine an ordinary two-dimensional table with spatial shp data for an excel sheet containing district and county information, combined with the corresponding spatial shp data, to realize the spatialization of two-dimensional data and give decision-making Or a distribution cognition on a geographical scale to better support economic services. This article will focus on how to use Qgis software to integrate the two, and finally draw a map based on the fusion results to get an intuitive result.

Guess you like

Origin blog.csdn.net/yelangkingwuzuhu/article/details/131147538