- Learn QGIS
- Andrew Cutts Anita Graser
- 536字
- 2021-06-10 19:19:57
Editing attribute data
With the AREA_MI <= 1000 selection, let's add a field and populate it with a marker based on this selection.
Click on the Field Calculator button in the attributes toolbar to open up the field calculator.
This window contains considerable information; there is a great deal of power within the field calculator. In our case, we want to create a new field called small_area and assign yes if it is =< 1000, or no if it is >1000. As with many of the tools in GIS, there are several ways of doing this. The method we will use is designed to help you to build confidence first. In chapter 6, Extending QGIS with Python, we will look at more complex queries and show how this particular query could be addressed in one step.
As shown in the following screenshot, the first check box is ticked. This tells QGIS to only apply the calculation to the selected data. The second check box tells QGIS to create a new field. We could update an existing one if we wanted, but at this point we want to build a new field and populate it. Set the field name to small_area and the type to Text.
Accept the defaults for field length and in the expression window type yes (including the single quotations). Your Field Calculator should now look like this:

By clicking on OK, you will have started an edit session and populated a field with yes based on your Selection by Value selection. Your screen will look similar to this:

In the Layers window, there is a pencil icon on the toolbar. This tells us that this layer is currently open in an edit session. Let's take a look at the attribute table; press F6 or click on the Attribute Table button in the attribute toolbar. It should look like this:

Congratulations! You have now created some data! Six-hundred and forty rows of data have now been updated with yes in the small_area field. But what about the remaining thirteen rows? They will now have no entry for the small_area field. Let's change that. Click on the Invert selection (Ctrl +R) button in the attribute table. It looks like this:

This will invert your selection. Once clicked, it may appear that you have lost everything. However, click on the button at the bottom left of the attribute table and click Show Selected Features. It will look like this:

Now we have effectively selected all features with an AREA_MA > 1000. You can see that the small_area values associated with this area are set to NULL:

You may have already noticed that the attribute toolbar is not only in the main display of QGIS, but it is also in the attribute table. In this toolbar, select the Field Calculator. This time we are going to set the selected rows to no. Remember, this time we are not creating a new field, but updating one.
Your field calculator should look similar to the following screenshot. We have highlighted the important difference compared to when you are creating a new field:

Click OK and then Clear Selection. Stop the editing session by clicking on the single pencil and then select yes to save the edits:

We have just edited attribute data in QGIS.
- Unreal Engine:Game Development from A to Z
- 嵌入式系統(tǒng)應(yīng)用
- Practical Data Wrangling
- 水晶石精粹:3ds max & ZBrush三維數(shù)字靜幀藝術(shù)
- MATLAB/Simulink權(quán)威指南:開(kāi)發(fā)環(huán)境、程序設(shè)計(jì)、系統(tǒng)仿真與案例實(shí)戰(zhàn)
- 網(wǎng)絡(luò)安全管理實(shí)踐
- 電腦上網(wǎng)輕松入門
- The DevOps 2.1 Toolkit:Docker Swarm
- 大數(shù)據(jù)導(dǎo)論
- 電腦故障排除與維護(hù)終極技巧金典
- Linux常用命令簡(jiǎn)明手冊(cè)
- 工業(yè)機(jī)器人技術(shù)
- 仿龜機(jī)器人的設(shè)計(jì)與制作
- 局域網(wǎng)組建與使用完全自學(xué)手冊(cè)
- 單片機(jī)原理、接口及應(yīng)用系統(tǒng)設(shè)計(jì)