azavea/python-sld — Issue #1: How to add multiple filters dynamically?
Author: rhansson
Created: 2012-01-11 02:21:22+00:00
State: open

Hi, appreciate the work very much.
My Python skills are a bit rusty but I can't seem to find a way to add multiple “AND” and “OR” filters dynamically!

My objective is to translate a parsed query string (SQL) to the corresponding SLD syntax. For example: "a > 1 and b < 2".
As far as I can tell, I must first create two separate filters for the rule:
import sld
# ...
r = fs.create_rule('r1')
f1 = sld.Filter(r)
f1.a = sld.PropertyCriterion(f1, 'PropertyIsGreaterThan')
f1.a.PropertyName = 'a'
f1.a.Literal = '1'
f2 = sld.Filter(r)
f2.b = sld.PropertyCriterion(f1, 'PropertyIsLessThan')
f2.b.PropertyName = 'b'
f2.b.Literal = '2'
and finally combine them like so:
r.Filter = f1 + f2

Now, how can I accomplish this when the number of criterion and operands are unknown? Essentially, I need to execute the Filter assignment dynamically but the filter references (f1 and f2) must already be defined!
Consider the following example: "(a > 1 and b < 2 and c = 3 ) or (d = 4 and e >= 5)"

Did I miss something? Thanks
--
Roland Hansson