Tell me more ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

First of all, sorry, I couldn't phrase my question better.

So I want to be able to add a new column in my attributes table, say B, and it's value should be 1 if Column A's value is 1 and 0 if Column A's value is 2. in other words:

If A==1 : B=1

elif A==2 : B=2 I couldn't figure out a way to do this using Field Calculator.

Thanks Trying to update "MineDeleteIt" values based on path_type

share|improve this question
After the THEN it should be 'Bike lane baby' and also 'some arbitrary text'. You need single quotes for strings – Nathan W Jan 23 at 4:36
You are right. I had added double quotes and it didn't make any difference. Thanks a lot for your patience! – Pey Man Jan 23 at 4:39
1  
Double quotes are for column names. Single quotes for strings. – Nathan W Jan 23 at 4:43
@NathanW Sorry for pushing this, but do if-else conditions work too? I'm getting errors, but if it's possible I'll figure it out myself... – Pey Man Jan 23 at 4:50
1  
Not yet. We haven't added support yet. Feel free to open at ticket at hub.qgis.org and assign it to me. I'm the only Nathan in the list. – Nathan W Jan 23 at 5:07
show 1 more comment

1 Answer

up vote 2 down vote accepted

You can use a case statement to do that:

CASE 
    WHEN "A" = 1 THEN 1 
    WHEN "A" = 2 THEN 2 
END

If you want everything else to match you can use ELSE

CASE 
    WHEN "A" = 1 THEN 1 
    WHEN "A" = 2 THEN 2
    ELSE 0
END

This way everything that is not A=1 or A=2 will get assigned 0.

share|improve this answer
thanks for your answer. Can you tell me where should I enter it though? should I use field Calculator? Because it says invalid expression... – Pey Man Jan 22 at 21:49
Which version of QGIS? – Nathan W Jan 23 at 0:35
it's 1.8. are u able to do it with field calculator? – Pey Man Jan 23 at 1:37
Yes. What does it say when you click (More INfo) – Nathan W Jan 23 at 3:56
it say's : Parser Error: syntax error, unexpected COLUMN_REF, expecting WHEN or ELSE or END Eval Error: No root node! Parsing failed? – Pey Man Jan 23 at 4:13
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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