From d0e84b14f6e9c19d4fe63f2b13c7bfdd31dfcd8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Sun, 17 May 2015 16:57:51 +0200 Subject: [PATCH 1/4] Mode standalone: when encoding to json, always use sane parameters --- pgmapcss/mode/standalone/footer.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pgmapcss/mode/standalone/footer.inc b/pgmapcss/mode/standalone/footer.inc index c6b5bf41..6abf45c5 100644 --- a/pgmapcss/mode/standalone/footer.inc +++ b/pgmapcss/mode/standalone/footer.inc @@ -199,7 +199,7 @@ if __name__ == '__main__': 'properties': properties_list, }} - return json.dumps(feature, indent=2) + return json.dumps(feature, indent=4, ensure_ascii=False) results = [] From 4d08882ff8e3ad656396a232a351d5392ee08769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Sun, 24 May 2015 10:41:50 +0200 Subject: [PATCH 2/4] Mode standalone: fix content-type --- pgmapcss/mode/standalone/footer.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pgmapcss/mode/standalone/footer.inc b/pgmapcss/mode/standalone/footer.inc index 6abf45c5..e0d65241 100644 --- a/pgmapcss/mode/standalone/footer.inc +++ b/pgmapcss/mode/standalone/footer.inc @@ -78,7 +78,7 @@ if __name__ == '__main__': parameters['srs'] = int(params.getvalue('srs')) # print HTML headers - print("content-type: text/javascript, charset-utf8") + print("content-type: application/javascript; charset-utf8") print() else: From 9dcc42ed4dceddfd75367ac17b186d555da193e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Sun, 24 May 2015 10:42:41 +0200 Subject: [PATCH 3/4] Mode standalone: fix CGI: use utf8-encoding on stdout --- pgmapcss/mode/standalone/footer.inc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pgmapcss/mode/standalone/footer.inc b/pgmapcss/mode/standalone/footer.inc index e0d65241..ea55ddac 100644 --- a/pgmapcss/mode/standalone/footer.inc +++ b/pgmapcss/mode/standalone/footer.inc @@ -77,8 +77,19 @@ if __name__ == '__main__': if params.getvalue('srs'): parameters['srs'] = int(params.getvalue('srs')) + if 'meta' in parameters: + include_meta = parameters['meta'] + + if bounds is None and include_meta != 'only': + print("No bounding box defined.") + sys.exit(1) + + # re-open stdout to use utf-8 encoding + import codecs + sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach()) + # print HTML headers - print("content-type: application/javascript; charset-utf8") + print("content-type: application/javascript; charset=utf-8") print() else: From 3a55a40285fcb8ad949eda5404b319af3bf3d5cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Mon, 25 May 2015 15:36:30 +0200 Subject: [PATCH 4/4] Eval::sum(): new eval function --- doc/eval.creole | 1 + pgmapcss/eval/eval_sum.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 pgmapcss/eval/eval_sum.py diff --git a/doc/eval.creole b/doc/eval.creole index 87095b1c..565b452c 100644 --- a/doc/eval.creole +++ b/doc/eval.creole @@ -89,6 +89,7 @@ If you read a number, unit conversion takes place. The following units are suppo | exp | v number | number | Return e raised to the power of v | no standard | min | number, [number, [number, ...]] | number | Returns lowest of the input values. | MapCSS 0.2 | max | number, [number, [number, ...]] | number | Returns highest of the input values. | MapCSS 0.2 +| sum | number, [number, [number, ...]] | number | Returns sum of all input values. | MapCSS 0.2 | metric | value | number | Converts the input to pixels (or ""). E.g. number('3m') => '1.5' when the scale is '2 meters in 1 pixel'. | MapCSS 0.2 | metric | value, [string] | number | Converts the input to a number (or "") of the specified unit (parameter 2, default 'px'). E.g. number('2px') => '2' or number('100px', 'm') => '238.86' (at zoom level 16). | no standard | zmetric | value | number | Currently not supported, returns '' | diff --git a/pgmapcss/eval/eval_sum.py b/pgmapcss/eval/eval_sum.py new file mode 100644 index 00000000..a76c4ab5 --- /dev/null +++ b/pgmapcss/eval/eval_sum.py @@ -0,0 +1,37 @@ +class config_eval_sum(config_base): + mutable = 3 + +def eval_sum(param): + if len(param) == 0: + return '' + if len(param) == 1: + param = param[0].split(';') + + values = [] + for v in param: + try: + v = float(v) + except ValueError: + v = '' + values.append(v) + + values = [ float(v) for v in values if v != '' ] + + if len(values) == 0: + return '' + + return float_to_str(sum(values)) + +# TESTS +# IN ['1.0', '5', '3'] +# OUT '9' +# IN ['1.0', ''] +# OUT '1' +# IN ['1;4;5'] +# OUT '10' +# IN [] +# OUT '' +# IN ['1;;5'] +# OUT '6' +# IN [''] +# OUT ''