2

I use QGIS to visualise my data but I use R when I have to do many treatments on my attribute tables. (package terra)

But when I write vector data with R, the Na's appear in QGIS attribute table as "nan" when it usually writes "NULL" in grey when the cell is blank. The columns remain considered as real though "nan" values are present.

It is a problem since I can't select attributes by the expressions "field" is null or "field" = "nan".

I tried to replace them with if("field" = "nan", NULL, "field") without success either.

Do you know a way to change these "nan" to NULL? Preferably on the R side.

1
  • I have tried to improve this in terra. It now writes NULL to files instead of NaN. Although the behavior may depend on the file format you use; and you do not provide much information. Perhaps you can try the development version (1.5-36) that you can install with: install.packages('terra', repos='https://rspatial.r-universe.dev') Commented May 24, 2022 at 1:12

1 Answer 1

4

I wouldn't be able to help with sorting this in R, however regarding the post-processing in QGIS, you current request in the field calculator is:

if("field" = "nan", NULL, "field")

which you said doesn't work. I would suggest to try either of the two following syntaxes:

if("field" = 'nan', NULL, "field")

or

if("field" = 'nan', "", "field")

and see if you get any better results.

1
  • if("field" = 'nan', NULL, "field") worked, thank you for your response.
    – Anthony
    Commented May 23, 2022 at 12:22

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.