Exemplo n.º 1
0
def make_map(map_output, scale=20000, x_center=622000, y_center=6406000):
    "Make a map as a function of the scale"

    # Compute the scale
    page_size = int(PAGE_FORMAT[1])
    f = math.sqrt(2)**PAGES[page_size]

    # increasing map_x and map_y lead to decreasing font and symbol size: not good
    map_x = int(f * 4600)  # 4600 is the number of pixels for an A4 length

    # if 460: zoom = 13
    map_y = int(map_x / math.sqrt(2))
    m = Map(map_x, map_y)
    load_map(m, MAPNIK_FILE)

    # Bounding box (expressed in EPSG:3857, meters)
    delta_x = f * 0.295 * scale / math.cos(LATITUDE * 2 * math.pi / 360)
    delta_y = delta_x / math.sqrt(2)
    xmin = x_center - delta_x / 2
    xmax = x_center + delta_x / 2
    ymin = y_center - delta_y / 2
    ymax = y_center + delta_y / 2

    bbox = (Envelope(xmin, ymin, xmax, ymax))
    m.zoom_to_box(bbox)
    print("Scale = " + str(m.scale()))

    render_to_file(m, map_output)