- 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.
- 現代測控系統典型應用實例
- PPT,要你好看
- 腦動力:C語言函數速查效率手冊
- 手把手教你學AutoCAD 2010
- Cloud Analytics with Microsoft Azure
- 微型計算機控制技術
- JMAG電機電磁仿真分析與實例解析
- 樂高創意機器人教程(中級 下冊 10~16歲) (青少年iCAN+創新創意實踐指導叢書)
- Maya 2012從入門到精通
- 深度學習中的圖像分類與對抗技術
- 工業機器人入門實用教程(KUKA機器人)
- Cloudera Administration Handbook
- Java Web整合開發全程指南
- Hands-On Reactive Programming with Reactor
- 無人駕駛感知智能