3

In QGIS 2.14.3 added a csv file as a layer. Attempt to add a virtual field like shown in the screenshot below (same result with "field_14" || ' ' || "field_10" || "field_11"):

enter image description here

The field is created but contains only NULL values:

enter image description here

If not a bug, what am I missing?

3 Answers 3

2

You are missing the field length. I don't know why you have Text, unbegrenzte Länge (text), I only can choose Text (string) with the ability to set the output field length to 10 or 100 or else.

With a given field length, it works for me. Same QGIS version, 64bit, Windows standalone and Linux Mint.


UPDATE

It seems to be a difference whether you add the CSV with Add delimited text, Add vector Layer, or by drag and drop from the browser. The first one shows your problem, the others do not.

2
  • Possible a slight misunderstanding, I just saw, that I can choose Text (string) when saving my CSV as a shapefile to which I add the virtual field. With CSV-Layers I can only select Text, unbegrenzte Länge (text). Seems the beahaviour of adding fields strongly depends on the data provider. With a shapefile I observe the same behaviour as described below under 2.15.0, so it will be necessary to catch NULL values before concatenation anyway. Commented Jun 28, 2016 at 12:00
  • It depends on how you add the CSV, see my extended answer.
    – AndreJ
    Commented Jun 28, 2016 at 14:56
1

In the screenshot you posted, you have selected the option for Output field type of "Text, unbegrentze Länge (text)", which Google translates as "Text, unlimited length". Since it is unlimited, precision and field length are set to a dummy value of -1.

I am also using QGIS 2.14.3 (on Linux Mint 17.2), but I do not have the option of this data type. I therefore can't test the error you are experiencing. I only have the option of "Text (string)". When I tested the concat() function using that data type, the virtual field was created successfully. My suggestion would be to try using the "Text (string)" data type with a large enough output field length to accommodate your data.

1

Meanwhile I tested this with 2.8.7LTR, 2.8.9LTR, 2.14.3, 2.15.0 on Win7, Win10, Win2008 R2, installed via OSGeo4w Installer or standalone. In all of these cases I can only select Text, unbegrenzte Länge (text) (unlimited Text). I explicitly do NOT have the option Text (string) with the ability to set the output field length to some value.

Examples:

2.8.7

enter image description here

2.14.3

enter image description here

2.15.0

enter image description here

Then, in 2.15.0 I made the interesting observation, that the virtual field is created correctly if field_11 is not NULL. So this means, that NULL values are not automatically treated as empty strings, when using them in a string concatenation (This is a matter of semantics, if I have NULL values in string concatenation I want them to be treated as empty strings as e.g. FME does.).

Obviously this means in versions <2.15.0 that the whole virtual field addition becomes erroneous, when errors occur in only some features.

So to get things work, it is necessary to test for NULL values befor concatenation like this:

enter image description here

With the expected result:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.