2012-01-08 14:01:54 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import mapnik
|
|
|
|
import sys
|
|
|
|
import os.path
|
2012-02-18 16:51:18 +00:00
|
|
|
from compare import compare, summary
|
2012-01-08 14:01:54 +00:00
|
|
|
|
2012-03-20 21:06:22 +00:00
|
|
|
defaults = {
|
|
|
|
'sizes': [(500, 100)],
|
|
|
|
'bbox': mapnik.Box2d(-0.05, -0.01, 0.95, 0.01)
|
|
|
|
}
|
|
|
|
|
|
|
|
sizes_many_in_big_range = [(800, 100), (600, 100), (400, 100),
|
|
|
|
(300, 100), (250, 100), (150, 100), (100, 100)]
|
|
|
|
|
|
|
|
sizes_few_square = [(800, 800), (600, 600), (400, 400), (200, 200)]
|
|
|
|
sizes_many_in_small_range = [(490, 100), (495, 100), (497, 100), (498, 100),
|
|
|
|
(499, 100), (500, 100), (501, 100), (502, 100), (505, 100), (510, 100)]
|
|
|
|
|
2012-03-09 01:01:51 +00:00
|
|
|
dirname = os.path.dirname(__file__)
|
2012-03-23 19:42:11 +00:00
|
|
|
|
2012-02-20 16:42:12 +00:00
|
|
|
files = [
|
2012-03-20 21:06:22 +00:00
|
|
|
{'name': "list", 'sizes': sizes_many_in_big_range},
|
|
|
|
{'name': "simple", 'sizes': sizes_many_in_big_range},
|
|
|
|
{'name': "lines-1", 'sizes': sizes_few_square},
|
|
|
|
{'name': "lines-2", 'sizes': sizes_few_square},
|
|
|
|
{'name': "lines-3", 'sizes': sizes_few_square},
|
|
|
|
{'name': "lines-shield", 'sizes': sizes_few_square},
|
|
|
|
{'name': "simple-E"},
|
|
|
|
{'name': "simple-NE"},
|
|
|
|
{'name': "simple-NW"},
|
|
|
|
{'name': "simple-N"},
|
|
|
|
{'name': "simple-SE"},
|
|
|
|
{'name': "simple-SW"},
|
|
|
|
{'name': "simple-S"},
|
|
|
|
{'name': "simple-W"},
|
2012-07-30 00:17:43 +00:00
|
|
|
{'name': "formatting"},
|
2012-03-20 21:06:22 +00:00
|
|
|
{'name': "formatting-1"},
|
|
|
|
{'name': "formatting-2"},
|
|
|
|
{'name': "formatting-3"},
|
|
|
|
{'name': "formatting-4"},
|
|
|
|
{'name': "expressionformat"},
|
|
|
|
{'name': "shieldsymbolizer-1", 'sizes': sizes_many_in_small_range},
|
|
|
|
{'name': "rtl-point", 'sizes': [(200, 200)]},
|
2012-03-20 22:12:39 +00:00
|
|
|
{'name': "jalign-auto", 'sizes': [(200, 200)]},
|
|
|
|
{'name': "line-offset", 'sizes':[(900, 250)],
|
2012-07-03 21:39:34 +00:00
|
|
|
'bbox': mapnik.Box2d(-5.192, 50.189, -5.174, 50.195)},
|
2012-08-01 23:12:52 +00:00
|
|
|
{'name': "orientation", 'sizes': [(800, 200)]},
|
|
|
|
{'name': "hb-fontsets", 'sizes': [(800, 200)]}
|
2012-03-15 23:38:03 +00:00
|
|
|
]
|
2012-02-17 22:19:07 +00:00
|
|
|
|
2012-04-04 21:54:07 +00:00
|
|
|
def render(filename, width, height, bbox, quiet=False):
|
|
|
|
if not quiet:
|
|
|
|
print "Rendering style \"%s\" with size %dx%d ... \x1b[1;32m✓ \x1b[0m" % (filename, width, height)
|
|
|
|
print "-"*80
|
2012-03-02 00:45:44 +00:00
|
|
|
m = mapnik.Map(width, height)
|
2012-03-20 20:28:21 +00:00
|
|
|
mapnik.load_map(m, os.path.join(dirname, "styles", "%s.xml" % filename), False)
|
2012-03-20 22:12:39 +00:00
|
|
|
if bbox is not None:
|
|
|
|
m.zoom_to_box(bbox)
|
|
|
|
else:
|
|
|
|
m.zoom_all()
|
2012-04-17 05:07:14 +00:00
|
|
|
expected = os.path.join(dirname, "images", '%s-%d-reference.png' % (filename, width))
|
|
|
|
if not os.path.exists('/tmp/mapnik-visual-images'):
|
|
|
|
os.makedirs('/tmp/mapnik-visual-images')
|
|
|
|
actual = os.path.join("/tmp/mapnik-visual-images", '%s-%d-agg.png' % (filename, width))
|
|
|
|
mapnik.render_to_file(m, actual)
|
|
|
|
diff = compare(actual, expected)
|
2012-03-02 00:45:44 +00:00
|
|
|
if diff > 0:
|
|
|
|
print "-"*80
|
2012-04-04 21:54:07 +00:00
|
|
|
print '\x1b[33mError:\x1b[0m %u different pixels' % diff
|
2012-03-02 00:45:44 +00:00
|
|
|
print "-"*80
|
2012-02-17 22:19:07 +00:00
|
|
|
|
2012-01-08 14:01:54 +00:00
|
|
|
return m
|
2012-02-24 21:13:56 +00:00
|
|
|
|
2012-04-04 21:54:07 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
if '-q' in sys.argv:
|
|
|
|
quiet = True
|
|
|
|
sys.argv.remove('-q')
|
|
|
|
else:
|
|
|
|
quiet = False
|
|
|
|
|
|
|
|
if len(sys.argv) == 2:
|
2012-07-03 21:39:34 +00:00
|
|
|
files = [{"name": sys.argv[1], "sizes": sizes_few_square}]
|
2012-04-04 21:54:07 +00:00
|
|
|
elif len(sys.argv) > 2:
|
2012-07-03 21:39:34 +00:00
|
|
|
files = []
|
2012-07-29 23:25:21 +00:00
|
|
|
for name in sys.argv[1:]:
|
2012-07-03 21:39:34 +00:00
|
|
|
files.append({"name": name})
|
2012-02-24 21:13:56 +00:00
|
|
|
|
2012-04-04 21:54:07 +00:00
|
|
|
for f in files:
|
|
|
|
config = dict(defaults)
|
|
|
|
config.update(f)
|
|
|
|
for size in config['sizes']:
|
|
|
|
m = render(config['name'], size[0], size[1], config['bbox'], quiet=quiet)
|
|
|
|
mapnik.save_map(m, os.path.join(dirname, 'xml_output', "%s-out.xml" % config['name']))
|
2012-01-24 23:00:09 +00:00
|
|
|
|
2012-04-04 21:54:07 +00:00
|
|
|
summary()
|