QGIS has something called forms to make it easier to change te attributes of an object. This article is about the use of these forms. As exampel we use a dutch dataset of the houses of the netherlands (BAG) which only contain geometries and not other attributes. These we are going to add ourself.
We start with a shapefile with the house geometries. With the Python Plugin ‘Table Manager’ of Borys Jurgiel it is pretty easy to add columns to the shape file. Just adding a name and a type of th column. It is also possible to change the order of the columns in the shape file.
In this way we created a shape file with attritutes to help us to do our imaginary ‘solar panel’ research. For every house we want to know if the user is interested in solar energy. And if that is the case, also check what other properties the house and it’s roof has.
Off course editing the values can be done by opening the attribute table and edit the values in this Excel like table:
But as stated earlier: QGIS has something called ‘forms’. A form for an object can be opened by clicking on that object.
Start with checking this possibility by going into Settings/Options dialogue. Select the ‘Map tools’ tab and check the option ‘Open feature form, if a single feature is identified’. Now a form will open when you use the i-tool and you are in editing modes.
Now to start editing the houses layer: make it active in the Legend. Start editing by pushing the little pencil button or by selecting the ‘Toggle editing’ menu item in the ‘Layer’ menu. After that, select an object by clicking on oen house. Because you are in the edit mode, you will not see the information in the normal way, but you will be shown the information in the form:
This standard form of QGIS gives you a textline for every attribute. QGIS will check values though. If you defined the type of an attribute as numerical, QGIS will not let you put text in that field.
But even better off course will be a form where you would have a checkbox if there is a yes/no question. Or a little calendar for a date field, or a dropdown menu if you have to choose between 4 different values possibilities.
To be able to see this kind of form, go to the properties of the layer and select the tab ‘Fields’. In here you will see the names and types of all attribute fields WITH the possibility to choose the type of edit widget.
In the screendump below for example I have made the FID column hidden, make the name field a normal line edit, and want a calendar when changing the date. A checkbox for wish (wens) en for the type of roof I want a ‘Value map’. In that dialogue I can choose if I want to give a list of values, of if I want to choose from all already available values or… have a look youself for all possiblities.
Now, when you select a house to see the input form, it will look like this:
That is more handy isn’t it? En there are even better ways. Nathan Woodrow has written about it ‘Custom feature forms with Python logic’. In this way you can make th forms even more intelligent: add for example checks for values against an online service or database. Or hide/show input values after changing another etc etc…
The plan is to write about this in a later article.