Пример #1
0
def multithread_render():
    mapniker = create_cartographer('mapnik',
                                   theme='./input/world.xml',
                                   image_type='png')
    threads = list()
    for i in range(4):
        thread = threading.Thread(target=render, args=(i, mapniker,))
        threads.append(thread)
        thread.start()
    for thread in threads:
        thread.join()
Пример #2
0
def benchmark():

    envelope = (-180, -85, 180, 85)
    size_list = [(256, 256), (512, 512), (1024, 1024), (2048, 2048)]

    mapniker = create_cartographer('mapnik',
                                   theme='./input/world.xml',
                                   image_type='jpeg')
    output_dir = r'output/mapnik_benchmark'
    if os.path.exists(output_dir):
        shutil.rmtree(output_dir)
    os.mkdir(output_dir)

    for size in size_list:
        output = os.path.join(output_dir, 'world_%dx%d.jpg' % size)
        with Timer():
            data = mapniker.render(envelope, size)
            with open(output, 'wb') as fp:
                shutil.copyfileobj(data, fp)
                data.close()