Failed in dynamic adding classes

myunghwa Hwang mhwang4 at UIUC.EDU
Mon Nov 13 19:47:29 PST 2006


By using a new feature of MapServer 4.9 +, i.e. OWSDispath,
I tried to dynamically add new classes into the original map file.
My code is the following:

#!/usr/local/bin/python

import cgi
import cgitb; cgitb.enable()
import mapscript as ms

cgi_queryitems = ['classitem', 'classification', 'numclass']
cgi_layers = ['bnd_1940', 'bnd_1950']

form = cgi.FieldStorage()

req = ms.OWSRequest()
# req.loadParams()

for key in form.keys():
     if key not in cgi_queryitems:
         req.setParameter(key, form[key].value)

map = ms.mapObj('/Users/myunghwa/Sites/Riverweb2/Riverweb.map')

for layer in cgi_layers:
     aLayer = map.getLayerByName(layer)
     firstClass = ms.classObj(aLayer)
     firstClass.name = "Total Population < 3000"
     firstClass.setExpression("([%s] < %s)" % ('poptotal', '3000') )
     firstStyle = ms.styleObj(firstClass)
     firstStyle.color.setRGB(0, 255, 0)
     firstStyle.outlinecolor.setRGB(0, 0, 255)
     aLayer.moveClassUp(1)
     secondClass = ms.classObj(aLayer)
     secondClass.name = "Total Population >= 3000"
     secondClass.setExpression("([%s] >= %s)" % ('poptotal', '3000') )
     secondStyle = ms.styleObj(secondClass)
     secondStyle.color.setRGB(0, 180, 0)
     secondStyle.outlinecolor.setRGB(0, 0, 255)
     aLayer.moveClassUp(2)
     aLayer.status = 1

map.OWSDispatch(req)

If I remove the second for loop, it worked well.
But if I include the second for, it just shows a white image.
If anybody knows why it happens, please let me know.
Or if you explain how OWSDispatch works, it'll be greatly helpful.

from Myunghwa Hwang



More information about the MapServer-users mailing list