Monday, 23 January 2017

mapserver - IN operator in FILTER in my Mapfile


I'd like to select multiple values on my column (undefined number) and as long as I know, IN operator doesn't work on Mapserver's filter.



Example : FILTER (([ct] IN ('%ct%')) or ('%ct%' = '1')) returns



msPostGISLayerWhichShapes(): Error (ERREUR: la fonction ct(unknown) n'existe pas LINE 1: ...0878906249999975 -66.4782081438564))',4326) and (("ct"('1'))...


HINT: Aucune fonction ne correspond au nom donné et aux types d'arguments. Vous devez ajouter des conversions explicites de type.



==> ct(unknown) function doesn't exist ... Can't find a function matching name and parameters given. You should add explicite type's conversions


Is there a tip to use IN operator? I need to send several values for a same column.


As my filter function could seem strange, here's my VALIDATION :


VALIDATION
'ct' '^[a-zA-Z\-]+$'

'default_ct' '1'
END

Answer



MapServer gets confused with this validation


VALIDATION
'ct' '^[a-zA-Z\-]+$'
'default_ct' '1'
END

The first line means "any string of any length that contain only ASCII letters in upper or lower case". However, on the second line the default value is set to '1' which does not validate by the regexp '^[a-zA-Z-]+$'.



You can either correct the regexp to accept also '1' or change the default to for example 'a'. FILTER must be edited to suit this change as or ('%ct%' = 'a').


The syntax of filters and expressions in MapServer is somewhat peculiar. Because your backend is PostGIS you can use the normal SQL syntax by forcing MapServer to use native filters. As documented in http://mapserver.org/mapfile/layer.html it is done with processing - ative filter directive




  • This directive can be used to do driver specific filtering. For database connections the string is a SQL WHERE clause that is valid with respect to the underlying database.



In your case use


PROCESSING "NATIVE_FILTER=ct in ('%ct%')"

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...