[Qgis-user] CASE Conditional in QGIS 2.0

Jürgen E. Fischer jef at norbit.de
Fri May 24 07:48:27 PDT 2013


Hi Larissa,

On Fri, 24. May 2013 at 16:06:31 +0200, Larissa Junek wrote:
> I'd like to use a CASE Conditional to update a field in OSM road data:

> CASE WHEN "type" = 'access_ramp' AND "maxspeed" IS NULL THEN 30 END

> This means that the field "maxspeed" shall be 30 for the access_ramp
> column. 
> 
> I inserted the SQL expression above and obvoiusly the CASE WHEN
> Conditional uses automatically an ELSE function, even if I don't insert
> one! In my case now the maxspeed only for 'access_ramp' is 30 and all
> the other features are set to NULL. It seems that the ELSE condition is
> set to NULL and that all the other data don't get the already existing
> value from the access_ramp column but are overwritten.
> 
> I don't want to have the other objects overwritten. Do I always have to
> use an ELSE expression? In which case can s.o. use the CASE expression
> only? Does somebody use it in practice?

The result of the expression doesn't control on which features the changes are
applied to.  So the expression must return something for all features.  And in
a CASE expression without an ELSE and with no true WHEN case is NULL.

So unless you filter the layer first or apply it only to selected features
after selecting all the 'access ramp' features, the expression is applied to
all features and nullifies all other features.  

You can still use

CASE WHEN "type" = 'access_ramp' AND "maxspeed" IS NULL THEN 30 ELSE "maxspeed" END



Jürgen 

-- 
Jürgen E. Fischer         norBIT GmbH               Tel. +49-4931-918175-31
Dipl.-Inf. (FH)           Rheinstraße 13            Fax. +49-4931-918175-50
Software Engineer         D-26506 Norden               http://www.norbit.de
committ(ed|ing) to Quantum GIS                         IRC: jef on FreeNode                         

-- 
norBIT Gesellschaft fuer Unternehmensberatung und Informationssysteme mbH
Rheinstrasse 13, 26506 Norden
GF: Jelto Buurman, HR: Amtsgericht Emden, HRB 5502




More information about the Qgis-user mailing list