QGIS 11 Modifying data

Robert Crowther Jun 2022

PrevNext

Maybe you have a map or map data, and you would like to refine the data. For example, the VectorMapDistrict data has a layer for ‘Woodland’. Perhaps you would like to show what kind of woodland e.g. ‘conifer’, ‘ancient’ or even as precise as ‘birch’? Good though the Ordinance Survey map‐data is, it does not contain this level of information. So you need to add the information to the base file data.

WARNING: How to approach modifying–duplication vs. attributes

If you’ve used a graphics editor, raster or vector, the natural way to split data is to duplicate a layer. Then work on each layer, filtering the information as you wish (‘ancient’ woodlands on one layer, ‘conifer’ on another) Well, a massive warning here. QGIS works from files. So if you duplicate layers, you are still working on the same base file. Delete from one ‘duplicated’ layer, and you’ll delete from the other layer also. If you know computer code, this is a variation of the old ‘shallow’ vs. ‘deep’ copy issue.

There’s reports all over the web, for many versions of QGIS, that copy and paste makes the same ‘shallow’ copy of data, so that’s no use either. And no, deep copy is not what ‘Layer Definition’ files are for. Layer Definition Files bundle styling with content, and will perform the same shallow copy.

There’s two ways I can think of to tackle this. Which you choose is for you to decide,

Clips

A QGIS clip must reform all lines crossing the clip edges, so QGIS will not try to track the data, but builds the data again. The upside to this method is that you can create many layers from one, so have ‘ancient woodland’, ‘conifer wpodland’ and ‘other woodland’ on separate layers. Editing one layer will not affect another. However, there are downsides to this method,

Add extra attributes, then make conditional styling

You add an extra attribute to the data in the ‘Woodland’ layer, called ‘TYPE’ or similar. Then make styles that target the attributes. The information on how to do this is in this section, look down. For data structure this is the usually the correct method. But this method also has downsides,

Clearly this will work amazingly well to isolate a couple of features for graphics, or correct an entry. But take one of my cases—I had over 4000 entries that needed general classification into maybe seven categories. That’s near possible this way. It’s enough to make you print off the map and start with Inkscape. Other power is needed.

Editing file data

There would seem to be two methods to edit base data,

Use editors on the base files

For example, some special editor for Shapefiles. In fact, the datafiles of a Shapefile are a spreadsheet style database, and will open in any spreadsheet editor. Or, for GML files, use an XML editor.

Discussion on editing the base files

This would seem to be the direct, fast, and power‐tool way to make map‐data edits. However, there are downsides, some weighty,

The end is that direct file editing may work to isolate a couple of features for graphics, or correct an entry. But is not often a good solution.

QGIS editing

Can QGIS edit the data in files? Then write to them? Yes. Indeed, all the information I’ve found online suggests QGIS editing as the route to take.

The Attributes Table

Like this,

Layer > Open Attribute Table

then,

[Button] New Field > [give a name, set the type of data]

One issue here is isolating which information we wsh to change. QGIS tries to help. It can pan to the selected attribute rows (CTRL‐J). If in view, the display will then indicate the selection on the map.

Clearly the attributes table can be used to isolate a couple of features for graphics, or correct an entry. But take one of my cases—I had over 4000 entries that needed general classification into maybe seven categories. That’s near possible this way. What would be needed would be the reverse of the above, which is to select on the map then highlight the rows. Far as I know, QGIS can not do this. However, QGIS has method for converting multiple attributes— you need to switch process then work through the interface.

Attributes multiple editing via the GUI

Select many features on a layer. Use one of the methods in the navigation and selection step. Then,

  1. [also button] Layer > Toggle Editing

  2. [also button] Edit > Modify Attributes of Selected Features

  3. [also button] Layer > Save Layer Edits

Note the last step—this edit will not be written to the file unless explicitly told (also, the edit can be cancelled).

Styling by attributes

Lets say you’d like to categorise one of the layers. Maybe you’d like to split ‘woodland’ by ‘type’?

Maybe first it is good to check, using a spreadsheet application, the .dbf file, see what data is there. If the data you want is there, but the styling is not, you will save a lot of work. But we’ll assume the data is not there.

Create a new field

Select the layer

  1. [Right click] Open the attribute table

  2. [button] Add Field

  3. Give a name and the type of data you want to store (this is just like a spreadsheet)

  4. Close the manager

Select features, modify field data

  1. [ensure ‘on’] Toggle Editing

  2. Select some features on the layer, see above

  3. [also button] Edit > Modify Attributes of Selected Features

  4. In the entry box for the new field, type in some data

  5. Press ok

  6. [!important] Save Edits

To style features by the new field and categories

  1. [also double‐click] Layer > Properties

  2. [select] Symbology

  3. Change to ‘rule‐based’

  4. [button] Add a rule

  5. Modify filter to ”PROVIDER” = ’oak’

  6. Make the symbol into an oak tree, or an oak‐coloured dot, or something

There’s an amazing button in the interface here, called ‘Test’. After you enter the rule, try use test, to see if you get any matches.

End of custom editing

Now we have a product, let’s do what we wanted to do for a long time, output