3

How can I tell mapserver to ignore a filter that is set in a mapfile?

I am displaying a wms layer with point features using mapserver. In one of the layers in my mapfile I have defined a filter similar to this:

FILTER          "mycolumn='%myvalue%'"

such that I can use runtime substitution in a mapserver request similar to this one:

http://someurl.com/mapserv?map=mymap.map&layer=mylayer&mode=map&myvalue=thisvalue

This works just fine.

However, sometimes I would like to display the entire dataset and thus forcing mapserver to ignore the filter.

Is it possible to deactivate the filter in a request?

3 Answers 3

3

I'm not sure, but this trick may work:

  1. Add FILTER to validation block of the layer's description, like this:

    LAYER
    ...
        VALIDATION
          'FILTER' '.'
        END
    ...
    
  2. When you want to show all of the data in your layer, add the following string to your URL request :

    &map.layer[mylayer]=FILTER+("[mycolumn]"+~*+".")
    

I hope this will help.

1
  • thanks a lot seruva19, your answer hinted in the right direction, helping me to get to the solution. I did not understand how yours works exactly...
    – yellowcap
    Commented Oct 9, 2012 at 19:25
3

A working solution is similar to what @seruva19 suggested. The trick is to add a boolean value to the filter as an alternative to the previous filter:

FILTER    "(mycolumn='%myvalue%') or %allvars%"

where the validation forces the value to be TRUE

VALIDATION
  ...
  "allvals"    "^TRUE$"
END

and the default of allvals is set to FALSE

METADATA
    ...
    'default_allvals'   'FALSE'
END
0

If I can help with this Answer. This two other solution.

Use a default value to void the filter clause.

VALIDATION
    myColumn'^[0-9]{1,2}$' 
    default_myColumn '0'
END

AND put the condition in the DATA

DATA "geometryColumn from (select * from MYTABLE where (('%myColumn%' = '0') or (myColumn='%myColumn%')) ) using srid 4326"

OR with a filter

Use a default value to void the filter clause.

VALIDATION
    myColumn'^[0-9]{1,2}$' 
    default_myColumn '0'
END
FILTER  ((('%myColumn%' = '0') or ([myColumn]='%myColumn%')))

Note than I expect an issue with single parenthesis with Oracle. I use double parenthesis to make it work correctly otherwise I got a full table scan. The debug show the Where clause with single parenthesis like that

WHERE   ( '0' = '0' ) OR ( myColumn= '0' )  AND …

with double parenthesis:

WHERE   (( '0' = '0' ) OR ( myColumn= '0' ))  AND …

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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