2

I would like to get a symbology using several columns. I have read that it was not possible to set up several fields within the CLASSITEM option in the mapfile. I have tried to do this in a different way but the layer is not displaying at all...

I'm using Mapserver 6.2.1. Here is a simplified extract of my mapfile's code :

CLASS
  NAME "Symbol 1"
  EXPRESSION (("[field1]"="01") && ("[field2]"="01"))
  STYLE
    SYMBOL circle
    COLOR 255 0 0
    SIZE 10
  END
END

CLASS
  NAME "Symbol 2"
  EXPRESSION (("[field1]"="02") && ("[field2]"="02"))
  STYLE
    SYMBOL circle
    COLOR 0 255 0
    SIZE 10
  END
END
  • Columns "field1" and "field2" are both strings, or what? – user30184 Sep 15 '14 at 9:44
  • Absolutely ! I had checked it out before posting. – wiltomap Sep 15 '14 at 11:09
  • The syntax of expressions is mystique but I have learned that almost everything is possible after rather a lot trial and error struggle. Try something like EXPRESSION ('[field1]'='02' AND '[field2]'='02'). – user30184 Sep 15 '14 at 11:37
  • Just tried these (without success) : EXPRESSION ('[field1]'='02' AND '[field2]'='02')EXPRESSION ("[field1]"="02" AND "[field2]"="02") EXPRESSION ('[field1]'='02') AND ('[field2]'='02') EXPRESSION ("[field1]"="02") AND ("[field2]"="02") EXPRESSION (('[field1]'='02') AND ('[field2]'='02')) EXPRESSION (("[field1]"="02") AND ("[field2]"="02")) EXPRESSION ("[field1]"='02' AND "[field2]"='02') EXPRESSION (("[field1]"='02') AND ("[field2]"='02')) Just can't find out what is wrong... – wiltomap Sep 15 '14 at 12:44
  • Which MapServer version, Windows or Linux? PostGIS or shapefile source or something else? – user30184 Sep 15 '14 at 12:49
2

Expressions in MapServer are rather messy from users point of view even the documentation at http://www.mapserver.org/mapfile/expressions.html may feel fine for MapServer developers.

What user must know is that datatypes matter and syntax is different for numbers and strings. For strings both the attribute name and its value must be quoted

EXPRESSION ('[field1]'='02')

For numbers syntax is without quotation

EXPRESSION ([field1]=02)

Expression that combines one string and one numeric field comes as

EXPRESSION ('[field1]'='02' AND [field2]>60)

Using wrong syntax may give correct result sometimes which is even more baffling for users. For a numeric attribute syntax ("[field3]" = "60") finds correct features because number "60" is found also with string comparison. However, string comparison ("[field3]" > "60") may not give desired result because "is lexicographically larger" is a fuzzy by definition and "7" is probably larger than "60".

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.