[mapserver-users] Filtering NULL values from Postgis Layer in Mapserver 7

Eichner, Andreas - SID Andreas.Eichner at sid.sachsen.de
Wed Aug 17 05:43:33 PDT 2016


Hello Marco,

IMHO the best solution would be to implement a "IS NULL" operator or function for the mapserver expressions. I guess this was not implemented because MS was originally developed for rendering ESRI-Shapefiles which do not support NULL values.

According to http://mapserver.org/cgi/runsub.html#table-of-contents LAYER/PROCESSING should support runtime substitution since 7.0 so you could try to use the 'NATIVE_FILTER' processing option with something like '%MY_VAR1% is not null and %MY_VAR2% is not null' (very much like your FILTER in MS 6.4):

PROCESSING "NATIVE_FILTER=%MY_VAR1% is not null and %MY_VAR2% is not null"

If that does not work (check the debug log if the statement build has substitutions applied) your only solution would be to use the DATA statement with a sub-select. Something like:

DATA "the_geom from (select gid, the_geom, %MY_VAR1% as attr1, %MY_VAR2% as attr2 from
      geotable where %MY_VAR1% is not null and %MY_VAR2% is not null) as subquery
      using unique gid using srid=4326"

Hopefully one of that works for you...

> -----Ursprüngliche Nachricht-----
> Von: mapserver-users [mailto:mapserver-users-bounces at lists.osgeo.org] Im
> Auftrag von deduikertjes
> Gesendet: Mittwoch, 17. August 2016 11:09
> An: mapserver-users at lists.osgeo.org
> Betreff: Re: [mapserver-users] Filtering NULL values from Postgis Layer in
> Mapserver 7
> 
> Andreas,
> 
> Thank you.
> 
> hmm, that's very interesting. Lets see if I understand correctly:
> 
> I observe that in the CLASS EXPRESSIONs in a Postgis layer NULL is treated
> as zero for numeric fields. So NULL gets visualized in the class where
> zero
> is visualized. In my opinion that is not very desirable. I actually would
> expect a default behaviour where NULL values will not match any CLASS
> EXPRESSION.
> 
> In Mapserver 6 we luckily had the FILTER option to filter out the NULL
> values to remedy this behaviour. Not very elegant but very doable.
> 
> Now in Mapserver 7 we lost the FILTER option and have to write a subselect
> in the DATA statement to get rid of NULL values. That seems to be a rather
> complicated solution for something which seems to be a very common task.
> 
> Or am I missing something and is there a way to avoid that NULL values end
> up as being treated as 0?
> 
> MArco
> 
> 
> 
> --
> View this message in context: http://osgeo-
> org.1560.x6.nabble.com/Filtering-NULL-values-from-Postgis-Layer-in-
> Mapserver-7-tp5280893p5281035.html
> Sent from the Mapserver - User mailing list archive at Nabble.com.
> _______________________________________________
> mapserver-users mailing list
> mapserver-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapserver-users


More information about the MapServer-users mailing list