Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/eval.creole
Original file line number Diff line number Diff line change
Expand Up @@ -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 '' |
Expand Down
37 changes: 37 additions & 0 deletions pgmapcss/eval/eval_sum.py
Original file line number Diff line number Diff line change
@@ -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 ''
15 changes: 13 additions & 2 deletions pgmapcss/mode/standalone/footer.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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: text/javascript, charset-utf8")
print("content-type: application/javascript; charset=utf-8")
print()

else:
Expand Down Expand Up @@ -199,7 +210,7 @@ if __name__ == '__main__':
'properties': properties_list,
}}

return json.dumps(feature, indent=2)
return json.dumps(feature, indent=4, ensure_ascii=False)


results = []
Expand Down