2012-01-08 15:01:54 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import mapnik
|
|
|
|
import sys
|
|
|
|
import os.path
|
2012-02-18 17:51:18 +01:00
|
|
|
from compare import compare, summary
|
2012-01-08 15:01:54 +01:00
|
|
|
|
2012-03-09 02:01:51 +01:00
|
|
|
dirname = os.path.dirname(__file__)
|
2012-02-20 17:42:12 +01:00
|
|
|
files = [
|
|
|
|
("list", 800, 600, 400, 300, 250, 200, 150, 100),
|
|
|
|
("simple", 800, 600, 400, 300, 250, 200, 150, 100),
|
2012-03-02 01:45:44 +01:00
|
|
|
("lines-1", (800, 800), (600, 600), (400, 400), (200, 200)),
|
2012-03-03 16:32:31 +01:00
|
|
|
("lines-2", (800, 800), (600, 600), (400, 400), (200, 200)),
|
2012-03-04 02:04:43 +01:00
|
|
|
("lines-3", (800, 800), (600, 600), (400, 400), (200, 200)),
|
|
|
|
("lines-shield", (800, 800), (600, 600), (400, 400), (200, 200)),
|
2012-02-20 17:42:12 +01:00
|
|
|
("simple-E", 500),
|
|
|
|
("simple-NE", 500),
|
|
|
|
("simple-NW", 500),
|
|
|
|
("simple-N", 500),
|
|
|
|
("simple-SE", 500),
|
|
|
|
("simple-SW", 500),
|
|
|
|
("simple-S", 500),
|
|
|
|
("simple-W", 500),
|
|
|
|
("formating-1", 500),
|
|
|
|
("formating-2", 500),
|
|
|
|
("formating-3", 500),
|
|
|
|
("formating-4", 500),
|
|
|
|
("shieldsymbolizer-1", 490, 495, 497, 498, 499, 500, 501, 502, 505, 510),
|
2012-03-16 00:38:03 +01:00
|
|
|
("expressionformat", 500),
|
|
|
|
("rtl-point", (200, 200))
|
|
|
|
]
|
2012-02-17 23:19:07 +01:00
|
|
|
|
2012-03-02 01:45:44 +01:00
|
|
|
def render(filename, width, height=100):
|
|
|
|
print "-"*80
|
|
|
|
print "Rendering style \"%s\" with size %dx%d ... " % (filename, width, height)
|
|
|
|
print "-"*80
|
2012-02-20 17:42:12 +01:00
|
|
|
width = int(width)
|
2012-03-02 01:45:44 +01:00
|
|
|
height = int(height)
|
|
|
|
m = mapnik.Map(width, height)
|
2012-01-08 15:01:54 +01:00
|
|
|
mapnik.load_map(m, os.path.join(dirname, "%s.xml" % filename), False)
|
|
|
|
bbox = mapnik.Box2d(-0.05, -0.01, 0.95, 0.01)
|
|
|
|
m.zoom_to_box(bbox)
|
2012-03-09 02:01:51 +01:00
|
|
|
basefn = os.path.join(dirname,'%s-%d' % (filename, width))
|
2012-02-18 17:51:18 +01:00
|
|
|
mapnik.render_to_file(m, basefn+'-agg.png')
|
|
|
|
diff = compare(basefn + '-agg.png', basefn + '-reference.png')
|
2012-03-02 01:45:44 +01:00
|
|
|
if diff > 0:
|
|
|
|
print "-"*80
|
|
|
|
print 'Error: %u different pixels' % diff
|
|
|
|
print "-"*80
|
2012-02-17 23:19:07 +01:00
|
|
|
|
2012-01-08 15:01:54 +01:00
|
|
|
return m
|
2012-02-24 22:13:56 +01:00
|
|
|
|
2012-02-20 17:42:12 +01:00
|
|
|
if len(sys.argv) == 2:
|
2012-03-07 01:35:37 +01:00
|
|
|
files = [(sys.argv[1], (500, 500))]
|
2012-02-20 17:42:12 +01:00
|
|
|
elif len(sys.argv) > 2:
|
|
|
|
files = [sys.argv[1:]]
|
2012-02-24 22:13:56 +01:00
|
|
|
|
2012-02-20 17:42:12 +01:00
|
|
|
for f in files:
|
|
|
|
for width in f[1:]:
|
2012-03-02 01:45:44 +01:00
|
|
|
if isinstance(width, tuple):
|
|
|
|
m = render(f[0], width[0], width[1])
|
|
|
|
else:
|
|
|
|
m = render(f[0], width)
|
2012-03-09 02:04:51 +01:00
|
|
|
mapnik.save_map(m, os.path.join(dirname,"%s-out.xml" % f[0]))
|
2012-01-25 00:00:09 +01:00
|
|
|
|
2012-02-18 17:51:18 +01:00
|
|
|
summary()
|