Using field calculator for attribute table data in QGIS

Trying to give an answer:

When adding a Delimited Text Layer (better switch to the english interface to have the correct terms at hand), you just create a connection to that file, not fully importing it. You can see that when you hover the mouse over the layer entry in the layers panel, showing a yellow pop-up after a while.

Completely imported layers like shp-files have their full paths shown there, with csv you see the path and kind of a query string like the ones you have when connecting to a database.

This was the standard way for adding delimited text data to QGIS. The drag-and drop way is fairly new and did not work for such data beforehand as I remember.

So the difference of the two scenarios might be:

  1. Add delimited data with coordinates (connection to that file only) and save afterwards to shp or whatever to be able to edit it.

  2. drag-and-drop any kind of tabular data, contained coordinates are just handled as attributes.

Leaving the quirks with csv aside, I think you should improve your workflow. CSV is definately not the format you would want to work with in a bigger scale. It has the charms of being human readable and is good for exports etc., but I think it's not very efficient and save doing more complex stuff with it, even if it is possible.

As you did not mention how those csv come to life, I expect that these are exports from other software. Check if there is a possibility to receive the data in another format. OpenOffice ODS-Files for example are easily added by drag-and-drop as well and editable afterwards.

3a. Why should you want to use the field calculator from the Toolbox and not just the one in the attribute table of your layer (Abacus-symbol)? There you can also add and delete fields. I think the field calculator in the Toolbox was recently added to be used with the modeller or to make changes to a layer and save the results to a new or temporary file (instead of changing the original)

3b. If you really need a processing tool to add fields besides of the field calculator, there is the "Refactor fields" function. But again, this will not make changes to your current layer, but "process" a new one.


Interesting! I don't usually drag and drop files, but I could add fields to a CSV layer when I tried this. Which feels wrong :)

The changes weren't saved when I committed the changes. I could only get the changes to commit if I saved it as a new CSV file using save as... (Tested on QGIS 2.16.3)

I usually use CSV as a quick way of getting data from python scripts into QGIS, by writing WKT into a CSV. I have to use TAB or pipe (|) as a delimiter because WKT contains commas. If you drag-and-drop you don't get the option to set the delimiter and it assumes commas.

Take a look at the layer capabilities with the different scenarios (use Layer Properties > Metadata and scroll down the Properties section to look for Capabilities)

If you import a delimited layer (with geometry) you should see...

Create Spatial Index, Fast Access to Features at ID, Curved Geometries

If I drag in a CSV file, or import one without a geometry, I see

Add Features

Notice that in both cases, there isn't an "Add attributes" capability. This might explain why I need to save as a new CSV.

The GDAL/OGR CSV driver doesn't allow in-place edits (no 'Add features' or 'Add attributes' capabilities).

I suspect that when you drag in a CSV file without a geometry, QGIS treats it as a text file. If you import a csv and the geometry is recognised, the GDAL/OGR driver is used, and it won't let you make edits.