Mapserver spatial filtering

2.4k views Asked by At

Anyone knows if there is a way to set a spatial filter in a mapfile to use with normal requests, not only WMS or WFS? I need this spatial filter to be any kind of polygon, not just rectangles, because these filters on our system are dynamic: users are allowed to draw polygons or select them from the polygon layers. It's a system where users use a legacy desktop application with no map capabilities, only requests Mapserver for images, so I have to do these filtering on the Mapserver side

To put it simply, here goes an example: users have layers with data like street names (labeled points) and districts (polygons). One of them may want to see only those streets that fall within district number two, so I want Mapserver to generate images hiding the rest of the streets. Of course, in the streets layer there is no information about in which district is located the street

Some things to help you ask this question:

  • Requests are cgi, not WMS but I could change that if it helps
  • I'm not using Mapscript nor any client like OpenLayers or uDig
  • Layers don't have and won't have attribute relations
  • I know about FILTER parameter in LAYER section but it's only for attribute filtering
  • I read about "Filter encoding" (included in SLD) but can't make it work, and it seems only for WFS
  • I've seen CQL but it's not supported in Mapserver directly, only through SLD

How do you do spatial filtering for image generation in Mapserver?

Thanks

2

There are 2 answers

0
geographika On

You could use WMS requests to return features within a bounding box.

See http://mapserver.org/ogc/wms_server.html

BBOX=minx,miny,maxx,maxy: Bounding box corners (lower left, upper right) in SRS units

A request would be similar to:

http://my.host.com/cgi-bin/mapserv?map=mywms.map&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&LAYERS=prov_bound&STYLES=&SRS=EPSG:4326&BBOX=-173.537,35.8775,-11.9603,83.8009&WIDTH=400&HEIGHT=300&FORMAT=image/png

Alternatively you could create queries in a spatial database (if you are using one), and pass in feature Ids and filter there.

0
Teng Ma On

There are generally two ways to do the spatial/non spatial query so far as i know of. First is using filter encoding such as using a parameter in the wms call url. e.g. http://.../mapserv?map=..&param=value

Another way to do this is by using a filter in the request body. Suppose you are able to make a post request to the server, you could use the filter for complex spatial/nonspatial query in one filter. For more details, please see the mapserver filter page. There are multiple spatial filter operations such as contain,intersects etc. available.

The filter inside the map file is a little bit different, it is predefined filter for the data source. This works when you have logic to filter data even before a customer request come in. (see more information by search OGC filter and CQL is for GeoServer currently)

And SLD works at the rendering time to filter the data as well. It does work on both spatial and non spatial filter as well. But it only reflect the getmap operation.