4

I'm using QGIS 2.4 pyclac and windows 7 OS. I have columns that should show NULL value but instead of that they show Zero (0) value, I need those fields to be NULL. This far I have seen a script that will solve my problem:

enter image description here

TIPO_USO is a string of characters, but VOL_COMER is double, so I need to pass it to NULL as the first field. I'll use the next script, using PyCalc:

enter image description here

Then I get this message:

Field code block does not return 'value' variable! Please declare this variable in your code!

Now I don't know what to do because I don't work with python but I'm sure this will solve my question, I hope :D

  • 2
    Do you want to use pycalc or are you open for other solutions? – underdark Aug 21 '14 at 22:48
  • 2
    Why is it that the function returns Wol_Comer for Vol_Comer != 0 and not Vol_Comer? The Wol_Comer field isn't in the list of parameters.. also, you're updating the field CODIGO not VOL_COMER, I think this is an oversight in getting the screen shot, but still it has to be mentioned. – Michael Stimson Aug 22 '14 at 2:28
  • my question have been solved, in both QGIS and ARCGIS (Which were my origynal question), the python code is very useful and I'll keep using it. For ArcGIS even if it is double all I need to do is write null in field calculator after I have loaded the shape into a GDB. Thanks Everyone for your support – Edixon Gutierrez Aug 22 '14 at 14:47
  • This would be better as a comment (and up-vote or accept) to the answer(s) that inspired it, not as an answer to your own Question :) – Erica Aug 22 '14 at 15:18
5

To make your field values NULL just type in NULL in your field calculator with the option to update only your selected records:

enter image description here

produces:

enter image description here

These images are from version 2.0.1 (Dufour) in English so may be a little different; the use of NULL has been around since I've been using QGIS (1.4).

  • The reference to Esri software was because this question sprang from another question about "how to do this in Esri" gis.stackexchange.com/questions/111346/… so I thought it was important to tie in this question back to the original question Matthais, normally I would not mention when one package was the same as another - it just confuses the issue. – Michael Stimson Aug 24 '14 at 21:47
2

Maybe it is a version issue (I don't know pyculator), but here the following code works:

if <VOL_COMER> == 0:
    value = None
else:
    value = <VOL_COMER>

or alternatively use a QgsExpression with the builtin field calculator

CASE
  WHEN "VOL_COMER" = 0 THEN NULL
  ELSE "VOL_COMER"
END
  • my question have been solved, in both QGIS and ARCGIS (Which were my origynal question), the python code is very useful and I'll keep using it. For ArcGIS even if it is double all I need to do is write null in field calculator after I have loaded the shape into a GDB. Thanks Everyone for your support – Edixon Gutierrez Aug 22 '14 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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