With the AREA_MI <= 1000selection,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:
Field Calculator
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:
An edit session in QGIS
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:
The attribute table with the selected features and the new field with the values populated
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:
Inverting a selection
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:
Show all features option
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:
Attribute table after inverted selection
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:
Field calculator shows how to update an existing field, with selected features set to No
Click OK and then Clear Selection. Stop the editing session by clicking on the single pencil and then select yes to save the edits: