Beispiel #1
0
      'render': lambda m, output, scale_factor: mapnik.render_to_file(m, output, 'png8:m=h', scale_factor),
      'compare': lambda actual, reference: compare(actual, reference, alpha=True),
      'threshold': 0,
      'filetype': 'png',
      'dir': 'images'
    },
    { 'name': 'cairo',
      'render': render_cairo,
      'compare': lambda actual, reference: compare(actual, reference, alpha=False),
      'threshold': cairo_threshold,
      'filetype': 'png',
      'dir': 'images'
    },
    { 'name': 'grid',
      'render': render_grid,
      'compare': lambda actual, reference: compare_grids(actual, reference, alpha=False),
      'threshold': 0,
      'filetype': 'json',
      'dir': 'grids'
    }
]

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

default_text_box = mapnik.Box2d(-0.05, -0.01, 0.95, 0.01)
Beispiel #2
0
            fail(actual_cairo,expected,str(e.message))
    if True:
        expected_grid = os.path.join(dirname, "grids", '%s-%d-reference.json' % (filename, width))
        actual_grid = os.path.join(visual_output_dir, '%s-grid.json' % actual)
        if not quiet:
            print "\"%s\" with size %dx%d with grid..." % (filename, width, height),
        try:
            grid = mapnik.Grid(m.width,m.height)
            mapnik.render_layer(m,grid,layer=0)
            utf1 = grid.encode('utf',resolution=4)
            open(actual_grid,'wb').write(json.dumps(utf1,indent=2))
            if not os.path.exists(expected_grid):
                # generate it on the fly
                fail(actual_grid,expected_grid,None)
            else:
                diff = compare_grids(actual_grid, expected_grid, threshold=1, alpha=False)
                report(diff,quiet)
        except Exception, e:
            sys.stderr.write(e.message + '\n')
            fail(actual_grid,expected,str(e.message))
    return m

if __name__ == "__main__":
    if '-q' in sys.argv:
       quiet = True
       sys.argv.remove('-q')
    else:
       quiet = False

    if len(sys.argv) == 2:
        files = [{"name": sys.argv[1], "sizes": sizes_few_square}]
Beispiel #3
0
      'render': lambda m, output, scale_factor: mapnik.render_to_file(m, output, 'png8:m=h', scale_factor),
      'compare': lambda actual, reference: compare(actual, reference, alpha=True),
      'threshold': 0,
      'filetype': 'png',
      'dir': 'images'
    },
    { 'name': 'cairo',
      'render': render_cairo,
      'compare': lambda actual, reference: compare(actual, reference, alpha=False),
      'threshold': 0,
      'filetype': 'png',
      'dir': 'images'
    },
    { 'name': 'grid',
      'render': render_grid,
      'compare': lambda actual, reference: compare_grids(actual, reference, alpha=False),
      'threshold': 0,
      'filetype': 'json',
      'dir': 'grids'
    }
]


def render(config, width, height, bbox, scale_factor, reporting):
    filename = config['name']
    m = mapnik.Map(width, height)
    postfix = "%s-%d-%d-%s" % (filename, width, height, scale_factor)

    try:
        mapnik.load_map(m, os.path.join(dirname, "styles", "%s.xml" % filename), False)
        if bbox is not None:
Beispiel #4
0
            dirname, "grids", '%s-%d-reference.json' % (filename, width))
        actual_grid = os.path.join(visual_output_dir, '%s-grid.json' % actual)
        if not quiet:
            print "\"%s\" with size %dx%d with grid..." % (filename, width,
                                                           height),
        try:
            grid = mapnik.Grid(m.width, m.height)
            mapnik.render_layer(m, grid, layer=0)
            utf1 = grid.encode('utf', resolution=4)
            open(actual_grid, 'wb').write(json.dumps(utf1, indent=2))
            if not os.path.exists(expected_grid):
                # generate it on the fly
                fail(actual_grid, expected_grid, None)
            else:
                diff = compare_grids(actual_grid,
                                     expected_grid,
                                     threshold=1,
                                     alpha=False)
                report(diff, quiet)
        except Exception, e:
            sys.stderr.write(e.message + '\n')
            fail(actual_grid, expected, str(e.message))
    return m


if __name__ == "__main__":
    if '-q' in sys.argv:
        quiet = True
        sys.argv.remove('-q')
    else:
        quiet = False