Support for > < >= <= in Komap

This commit is contained in:
Komяpa 2010-11-28 14:30:28 +02:00
parent b15bbe59d7
commit 61b67520a2
4 changed files with 39 additions and 21 deletions

View file

@ -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) &lt; %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) &lt;= %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] &lt; %s'%(params[0], float(params[1]))
return '[%s__num] &lt; %s'%(params[0], float(params[1]))
if t == '<=':
return '[%s] &lt;= %s'%(params[0], float(params[1]))
return '[%s__num] &lt;= %s'%(params[0], float(params[1]))
if t == '>':
return '[%s] &gt; %s'%(params[0], float(params[1]))
return '[%s__num] &gt; %s'%(params[0], float(params[1]))
if t == '>=':
return '[%s] &gt;= %s'%(params[0], float(params[1]))
return '[%s__num] &gt;= %s'%(params[0], float(params[1]))
#return ""
except KeyError:
pass

View file

@ -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"}):

View file

@ -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:

View file

@ -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]))