I have MapServer setup to display data (both WMS and WFS), however I'm having a problem adding a default filter.

There's is an area on the map that users should not be able to retrieve features from. I have the coordinates of this area so basically, I need to setup a default spatial filter to exclude features that are contained within this area. Removing the data itself isn't an option.

The layers are all OGR layers.

I can construct a client side filter to do this, however this should really be a server-side setting.

How should I go about doing this?

Ignoring the spatial requirement for a second, I'm having problems getting even a basic filter to work. If I append the following to the URL of a WFS request, this filter works as expected:

(Note this filter has no actual relevance, it's just a simple filter so I can check if it's being applied)


However, if in the map file I set the following:

LAYER ... FILTER "<PropertyIsGreaterThan><PropertyName>ID</PropertyName><Literal>916</Literal></PropertyIsGreaterThan>" ... END

Then I get no results from any query on that layer. Wrapping the filter in <Filter> tags has the same result.

I've also tried similar with the wfs_filter property, which doesn't seem to have any affect at all. (If I understand correctly, this is only used when using MapServer as a WFS Client?)

I'd appreciate any help.

Thanks :)


The filter you are trying to apply can only be applied from the client side. To apply a filter on the server side, you have to use an EXPRESSION at the CLASS level or a FILTER at the LAYER level. Note that spatial filter/expression may not work in FILTER. Here's an example:

    DATA ....shp
    NAME "test"
        NAME "test"
        EXPRESSION       ([shape] disjoint fromText('POLYGON((0 0,0 90,180 90,180 0,0 0))'))

Refer to the EXPRESSION documentation for more details: http://mapserver.org/mapfile/expressions.html

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.