Skip to content

Instantly share code, notes, and snippets.

@akhilrs
Forked from iambibhas/kolkata-zoom-14.py
Created September 25, 2017 01:42
Show Gist options
  • Save akhilrs/ba4be058e89d519719f28aa6eb51facc to your computer and use it in GitHub Desktop.
Save akhilrs/ba4be058e89d519719f28aa6eb51facc to your computer and use it in GitHub Desktop.

Revisions

  1. Bibhas revised this gist Apr 26, 2014. 1 changed file with 19 additions and 19 deletions.
    38 changes: 19 additions & 19 deletions kolkata-zoom-14.py
    Original file line number Diff line number Diff line change
    @@ -14,25 +14,25 @@
    resultImage = Image.new("RGBA", (xsize * 256, ysize * 256), (0,0,0,0))
    counter = 0
    for x in range(xmin, xmax+1):
    for y in range(ymin, ymax+1):
    for layer in layers:
    url = layer.replace("!x", str(x)).replace("!y", str(y)).replace("!z", str(zoom))
    match = re.search("{([a-z0-9]+)}", url)
    if match:
    url = url.replace(match.group(0), random.choice(match.group(1)))
    print url, "... ";
    try:
    req = urllib2.Request(url, headers={'User-Agent': 'BigMap/2.0'})
    tile = urllib2.urlopen(req).read()
    except Exception, e:
    print "Error", e
    continue;
    image = Image.open(io.BytesIO(tile))
    resultImage.paste(image, ((x-xmin)*256, (y-ymin)*256), image.convert("RGBA"))
    counter += 1
    if counter == 10:
    time.sleep(2);
    counter = 0
    for y in range(ymin, ymax+1):
    for layer in layers:
    url = layer.replace("!x", str(x)).replace("!y", str(y)).replace("!z", str(zoom))
    match = re.search("{([a-z0-9]+)}", url)
    if match:
    url = url.replace(match.group(0), random.choice(match.group(1)))
    print url, "... ";
    try:
    req = urllib2.Request(url, headers={'User-Agent': 'BigMap/2.0'})
    tile = urllib2.urlopen(req).read()
    except Exception, e:
    print "Error", e
    continue;
    image = Image.open(io.BytesIO(tile))
    resultImage.paste(image, ((x-xmin)*256, (y-ymin)*256), image.convert("RGBA"))
    counter += 1
    if counter == 10:
    time.sleep(2);
    counter = 0

    draw = ImageDraw.Draw(resultImage)
    draw.text((5, ysize*256-15), attribution, (0,0,0))
  2. Bibhas created this gist Apr 26, 2014.
    43 changes: 43 additions & 0 deletions kolkata-zoom-14.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    #!/usr/bin/env python
    # Generated by BigMap 2. Permalink: http://bigmap.osmz.ru/bigmap.php?xmin=12200&xmax=12231&ymin=7120&ymax=7143&zoom=14&scale=256&tiles=mapnik

    import io, urllib2, datetime, time, re, random
    from PIL import Image, ImageDraw
    # ^^^^^^ install "python-pillow" package | pip install Pillow | easy_install Pillow

    (zoom, xmin, ymin, xmax, ymax) = (14, 12200, 7120, 12231, 7143)
    layers = ["http://tile.openstreetmap.org/!z/!x/!y.png"]
    attribution = 'Map data (c) OpenStreetMap'
    xsize = xmax - xmin + 1
    ysize = ymax - ymin + 1

    resultImage = Image.new("RGBA", (xsize * 256, ysize * 256), (0,0,0,0))
    counter = 0
    for x in range(xmin, xmax+1):
    for y in range(ymin, ymax+1):
    for layer in layers:
    url = layer.replace("!x", str(x)).replace("!y", str(y)).replace("!z", str(zoom))
    match = re.search("{([a-z0-9]+)}", url)
    if match:
    url = url.replace(match.group(0), random.choice(match.group(1)))
    print url, "... ";
    try:
    req = urllib2.Request(url, headers={'User-Agent': 'BigMap/2.0'})
    tile = urllib2.urlopen(req).read()
    except Exception, e:
    print "Error", e
    continue;
    image = Image.open(io.BytesIO(tile))
    resultImage.paste(image, ((x-xmin)*256, (y-ymin)*256), image.convert("RGBA"))
    counter += 1
    if counter == 10:
    time.sleep(2);
    counter = 0

    draw = ImageDraw.Draw(resultImage)
    draw.text((5, ysize*256-15), attribution, (0,0,0))
    del draw

    now = datetime.datetime.now()
    outputFileName = "map%02d-%02d%02d%02d-%02d%02d.png" % (zoom, now.year % 100, now.month, now.day, now.hour, now.minute)
    resultImage.save(outputFileName)