QGIS Field and layer editing

Robert Crowther Aug 2023

I’m no expert on this. But the mess of notes below justifies an article.

QGIS Quirks

I run QGIS in a GTK environment. Some would say I deserve all I get for relying on shared libries and common standards. However, this usually works ok for me, and I’m not sure the issues are about the unnatural environment. Some notes,

Field and layer views

Two types of layer view interface, table and form

QGIS offers two types of interface to the field data,

Both can be seen in the ‘Attribute Table’ which can be switched from one view to the other. Both GUIs have their advantages and disadvantages. The table offers an overview of the data, with multiple field data on one page. It’s good for selection and quick editing of data. But with so much data, it’s limited in it’s display ability and editing. The forms offer more detail on single fields, in a more human interface that can use helpful input widgets e.g. to supply consistently formatted dates. But a form can only handle one field record at a time. The fact QGIS offers both GUIs is a demonstration of how QGIS has put a lot of work into this, and how it’s GUIs are advanced.

The ‘Identify’ Tool

From the menus,

View > ‘Identify Features’

or from a button that looks like a modified magnifier.

This is for viewing the data in a feature. It is a viewer, no editing from here. But it becomes handy as a shortcut from the map, as opposed to delving the Attribute Table for certain features.

Field attributes

Type

These are the usual database types, widened for the many different storage types QGIS handles like ShapeFiles, real databases, remote connections, and so forth. So they are,

and so on. It’s a comprehensive system, which means there are a couple of oddities like ‘Binary object (BLOB)’, and ‘JSON (string)’.

An interest for many may be how to handle big character fields and HTML. QGIS seems to manage these inputs not as field ‘types’, but using ‘text (string)’ fields and special widgets.

Name

Database people take great care over field names. They keep them short and think hard about them before they create them. This is because changing a field name is a painful exercise in many databases, which often includes backup migrations and cascading interactions with other software systems.

However, QGIS GUIs make changing field names as easy as I have ever seen. Call your field ‘description’ for human readability, or ‘desc’ because you are database designer and it’s a reflex to keep it short, no problem. The title is easy to change later. Have a look at some other layers, see what they do.

Field general handling

Create

Ok, there are many places to create a new field. Most obvious,

Pick a layer > [double click] ‘Properties’ > [choose tab] ‘Fields’ > [button] ‘New Field’

Will show a dialogue. Fill in, press ‘OK’.

Another place is the ‘Field Calculator’, which can create a new field from data calculated from other fields, See below.

And the ‘Attribute Table’ also has a button, which probably goes to the same code, for ‘New Field’.

Reorder

Why on earth would you want to reorder fields? Well, there are two reasons I can think of. First, if you are entering data into a table from somewhere else, especially hard copy like paper, you will want all the help you can get, especially having the same column order in the Attribute Table as on paper. Second, column order is sometimes affects output. For example, QGIS2Web prints popup label data in order of source fields.

Anyway, there is a way to do this. It creates a new layer (ShapeFile, Geopackage table etc.). But I’m sure if I could get this to work, I would not mind that,

Processing > Toolbox > Vector Table > Refactor Fields

And it does work.

Deletion

Remarkably easy, especially when you consider how much data may be deleted,

Editing

The only attribute of a field that can be easily changed through the GUI is the name.

This can be awkward. What if you created a ‘description’ field, but then wanted to extend the length of the field to allow longer descriptions? Can’t be done. However, what you can do is create a new field with the extended length, then use the ‘Field Calculator’ to fill it with the data already entered.

Then you ask, “How do I extend the length of the field, but keeping the same name?” Or change another attribute of the field, such as ‘type’? Again, you can’t. What you can do, though, is the computer data shuffle. That is,

Ok, it’s unusual to need to think about this but computers do it all the time.

The Field Calculator

This is an incredibly powerful feature of QGIS. It allows to run expressions on field data, use the results to fill new fields, or modify old fields.

I will not delve into the power here. Here we are talk about managing fields and field data. Here is how to use the field calculator to populate one field with data from another,

There, now you can shuffle data between fields (and much the same to update an existing field).

Field entry widgets

Are edited in,

[Select the new…] Layer > [double click] Properties > Attribute Form

Classification fields

A typical database activity, to add a field for class. For example, maybe you want to classify your local bin points as ‘clothing’, ‘recyclable’, ‘general waste’ etc.

You can use a text field (well, some database people would use a numeric representation, see below). Then you may think you use the ‘classify’ widget. On the whole, no. The ‘classify’ widget works from the table symbology. We are also considering general editing and new tables, so it’s unlikely you will have a classified symbology available. A solution, but not general. No, you need a ‘values’ widget. That will let you create a consistent set of text values that can be chosen from a select widget to fill the field.

Of course, you could be professional by making a number type field, then using the ‘enumeration’ widget. That will be more efficient on data storage and searching, but less human‐readable.

URLs

There is something called an HTML widget. I don’t know what it’s for or how to work it (is it for HTML‐formatted input?). Storing data as a link is something else.

To store link/URL data, use a text field. That will be ok. Whatever your intended final usage, fill with a full (absolute) URL. If you do that, the text will be recognized as links and the links will be formatted by the ‘Identify’ tool as clickable.

HTML entry

I think this opens the opportunity for HTML input to text fields?

Goto,

[Select the new…] Layer > [double click] Properties > Attribute Form

Choose a ’text’ field. Under ‘Widget Type’, which should be stet to ‘Text Edit’, are two checkboxes, ‘Multiline’ and ‘HTML’. The ‘HTML’ checkbox is displayed inset to show that it will only become possible if ‘Multiline’ is checked. Check both boxes.

Fields with this widget display in the ‘Attribute Table’ table display as,

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML

Gosh.

Overall

If there is any problem with QGIS’s GUI for layers (and thus databases), they are,

the different controls are found in different places

The best place to edit field attributes is in ‘layer properties’. Best place to see the attribute table is if you know where the button is. And so on

setting up more complicated fields, especially with form widgets is awkward

Switch to ‘Properties > Attributtes Form’

that a field without geometry can’t be given a geometry

Far as I know. It’s hidden from the user

Once you find everything though, it’s an impressive system, far in advance of anything I’ve encountered before. Plainly a huge effort to create but, finally, pleasant to use.

Refs

QGIS tutorial on web map creation. Includes some hints about field data, and how it may be rendered,

https://www.qgistutorials.com/en/docs/3/web_mapping_with_qgis2web.html

Reorder fields. Proper answer is some way down, other reorder attribute table view,

https://gis.stackexchange.com/questions/240258/changing-fields-order-in-qgis