I'm trying to filter a layer (using mapserver) backed by a Shapefile using layerObj.setFilter() but this doesn't seem to have any effect on the returned tile(s).
Sample code:
layerObj = mapserver.layerObj()
layerObj.setFilter("id = 1)
What am I doing wrong? Nothing blows up per say and mapserver produces tile(s) but they are the same set of tiles as if I had not applied the filter at all. Even applying the filter in the mapfile using FILTER "id = 1" also has no effect.
Here is a more detailed (in code) example of what I'm doing:
def index(self, *args, **kwargs):
mapObj = mapscript.mapObj(self.mapfile)
layers = [layer.strip().split(":", 1) for layer in kwargs["layers"].split(",")]
# create layers
for i, (layerType, layerName) in enumerate(layers):
layerObj = mapObj.getLayerByName("raster" if layerType == "models" else "vector").clone()
layerObj.name = "{0:s}:{1:s}".format(layerType, layerName)
layerObj.data = str(self.models.join(layerName)) if layerType == "models" else str(self.regions.join(layerName))
if "filter" in kwargs:
layerObj.setFilter(kwargs.pop("filter"))
mapObj.insertLayer(layerObj)
owsReq = mapscript.OWSRequest()
# add query string parameters into map request object
for k, v in kwargs.items():
owsReq.setParameter(k.upper(), v)
# write mapserver results to buffer
mapscript.msIO_installStdoutToBuffer()
try:
mapObj.OWSDispatch(owsReq)
except:
return SException(self.response, str(sys.exc_info()[1]))
# adjust content-type
self.response.headers["Content-Type"] = mapscript.msIO_stripStdoutBufferContentType()
output = mapscript.msIO_getStdoutBufferBytes()
self.response.headers["Content-Length"] = str(len(output))
# output WMS image data
return output