diff --git a/src/mapcss/Condition.py b/src/mapcss/Condition.py index 5b8e385..d04c66e 100644 --- a/src/mapcss/Condition.py +++ b/src/mapcss/Condition.py @@ -40,7 +40,11 @@ class Condition: if self.params[0][:2] == "::": return [] return set([self.params[0]]) - + def get_numerics(self): + if self.type in ("<", ">", ">=", "<="): + return self.params[0] + else: + return False def test(self, tags): """ Test a hash against this condition @@ -126,13 +130,13 @@ class Condition: return params[0], '"%s" IS NULL'%(params[0]) if t == '<': - return params[0], """(CASE WHEN "%s" ~ E'^[[:digit:]]+(\.[[:digit:]]+)?$' THEN CAST ("%s" AS FLOAT) ELSE 0 END) < %s"""%(params[0],params[0],params[1]) + return params[0], """(CASE WHEN "%s" ~ E'^[[:digit:]]+([.][[:digit:]]+)?$' THEN CAST ("%s" AS FLOAT) ELSE 0 END) < %s"""%(params[0],params[0],params[1]) if t == '<=': - return params[0], """(CASE WHEN "%s" ~ E'^[[:digit:]]+(\.[[:digit:]]+)?$' THEN CAST ("%s" AS FLOAT) ELSE 0 END) <= %s"""%(params[0],params[0],params[1]) + return params[0], """(CASE WHEN "%s" ~ E'^[[:digit:]]+([.][[:digit:]]+)?$' THEN CAST ("%s" AS FLOAT) ELSE 0 END) <= %s"""%(params[0],params[0],params[1]) if t == '>': - return params[0], """(CASE WHEN "%s" ~ E'^[[:digit:]]+(\.[[:digit:]]+)?$' THEN CAST ("%s" AS FLOAT) ELSE 0 END) > %s"""%(params[0],params[0],params[1]) + return params[0], """(CASE WHEN "%s" ~ E'^[[:digit:]]+([.][[:digit:]]+)?$' THEN CAST ("%s" AS FLOAT) ELSE 0 END) > %s"""%(params[0],params[0],params[1]) if t == '>=': - return params[0], """(CASE WHEN "%s" ~ E'^[[:digit:]]+(\.[[:digit:]]+)?$' THEN CAST ("%s" AS FLOAT) ELSE 0 END) >= %s"""%(params[0],params[0],params[1]) + return params[0], """(CASE WHEN "%s" ~ E'^[[:digit:]]+([.][[:digit:]]+)?$' THEN CAST ("%s" AS FLOAT) ELSE 0 END) >= %s"""%(params[0],params[0],params[1]) except KeyError: pass def get_mapnik_filter(self): @@ -159,13 +163,13 @@ class Condition: return '[%s] = \'\''%(params[0]) if t == '<': - return '[%s] < %s'%(params[0], float(params[1])) + return '[%s__num] < %s'%(params[0], float(params[1])) if t == '<=': - return '[%s] <= %s'%(params[0], float(params[1])) + return '[%s__num] <= %s'%(params[0], float(params[1])) if t == '>': - return '[%s] > %s'%(params[0], float(params[1])) + return '[%s__num] > %s'%(params[0], float(params[1])) if t == '>=': - return '[%s] >= %s'%(params[0], float(params[1])) + return '[%s__num] >= %s'%(params[0], float(params[1])) #return "" except KeyError: pass diff --git a/src/mapcss/Rule.py b/src/mapcss/Rule.py index a3ad858..e406ee5 100644 --- a/src/mapcss/Rule.py +++ b/src/mapcss/Rule.py @@ -61,7 +61,12 @@ class Rule(): for condition in self.conditions: a.update(condition.get_interesting_tags()) return a - + def get_numerics(self): + a = set() + for condition in self.conditions: + a.add(condition.get_numerics()) + a.discard(False) + return a def get_sql_hints(self, obj, zoom): if obj: if (self.subject!='') and not _test_feature_compatibility(obj, self.subject, {":area":"yes"}): diff --git a/src/mapcss/StyleChooser.py b/src/mapcss/StyleChooser.py index 149fad1..0a35cd2 100644 --- a/src/mapcss/StyleChooser.py +++ b/src/mapcss/StyleChooser.py @@ -49,6 +49,17 @@ class StyleChooser: self.stylepos=0 + def get_numerics(self): + """ + Returns a set of number-compared values. + """ + a = set() + for c in self.ruleChains: + for r in c: + a.update(r.get_numerics()) + a.discard(False) + return a + def get_interesting_tags(self, type, zoom): """ Returns a set of tags that were used in here. @@ -77,10 +88,7 @@ class StyleChooser: for r in c: p = r.get_sql_hints(type, zoom) if p: - #print p - q = "("+p[1] + ")"#[t[1] for t in p] - #print q if q == "()": q = "" if b and q: diff --git a/src/mapcss/__init__.py b/src/mapcss/__init__.py index 6488de8..081249d 100644 --- a/src/mapcss/__init__.py +++ b/src/mapcss/__init__.py @@ -313,10 +313,10 @@ def parseCondition(s): log.debug("condition NE: %s = %s"%(a[0], a[1])) return Condition('ne' ,a) ## FIXME: convert other conditions to python - if CONDITION_GT.match(s): - a = CONDITION_GT.match(s).groups() - log.debug("condition GT: %s > %s"%(a[0], a[1])) - return Condition('>' ,a) + if CONDITION_LE.match(s): + a = CONDITION_LE.match(s).groups() + log.debug("condition LE: %s <= %s"%(a[0], a[1])) + return Condition('<=' ,a) if CONDITION_GE.match(s): a = CONDITION_GE.match(s).groups() log.debug("condition GE: %s >= %s"%(a[0], a[1])) @@ -325,10 +325,11 @@ def parseCondition(s): a = CONDITION_LT.match(s).groups() log.debug("condition LT: %s < %s"%(a[0], a[1])) return Condition('<' ,a) - if CONDITION_LE.match(s): - a = CONDITION_LE.match(s).groups() - log.debug("condition LE: %s <= %s"%(a[0], a[1])) - return Condition('<=' ,a) + if CONDITION_GT.match(s): + a = CONDITION_GT.match(s).groups() + log.debug("condition GT: %s > %s"%(a[0], a[1])) + return Condition('>' ,a) + if CONDITION_REGEX.match(s): a = CONDITION_REGEX.match(s).groups() log.debug("condition REGEX: %s = %s"%(a[0], a[1]))