Skip to content

Instantly share code, notes, and snippets.

@vadimii
Created January 19, 2012 08:32
Show Gist options
  • Save vadimii/1638775 to your computer and use it in GitHub Desktop.
Save vadimii/1638775 to your computer and use it in GitHub Desktop.
Draw points on map with PIL
import Image
import ImageDraw
# For gsheet module see https://gist.github.com/1638779
import gsheet
# First param is spreadsheet ID and second param is sheet ID
WSHEET='0Atgd-n28fU3PdFFHSzJDNDhTS3NDMGx1NWNEdWNpOEE', 2
CCSHEET='0Atgd-n28fU3PdGlsMTdLRUFqR3JvbktmcWhqTFpSZmc', 0
# Second param is column index in sheet
# SPORT='biatlon', 11
# SPORT='bobsley', 12
# SPORT='gorlyzh', 13
# SPORT='kyorling', 14
# SPORT='konki', 15
# SPORT='lyzhndvoe', 16
# SPORT='lyzhngonki', 17
# SPORT='pryzhkinalyzh', 18
# SPORT='sanny', 19
# SPORT='skeleton', 20
# SPORT='snoubord', 21
# SPORT='figkatan', 22
# SPORT='fristail', 23
# SPORT='hokkey', 24
SPORT='shorttrek', 25
def readcities(data):
res = set()
for l in data[1:]:
if len(l)>SPORT[1] and l[SPORT[1]].strip():
res.add(l[7].strip())
return res
wcities = readcities(gsheet.load(*WSHEET))
point_blue = Image.open("point_blue.png")
point_size = (100, 100)
point_blue.thumbnail(point_size, Image.ANTIALIAS)
city_points = {}
city_points_data = gsheet.load(*CCSHEET)
for ld in city_points_data[1:]:
if len(ld)>2 and ld[0] and ld[2]:
city = ld[0]
x, y = ld[2].split(',')
city_points[city] = int(x), int(y)
canvas = Image.open('russia-map.winter.tif')
draw = ImageDraw.Draw(canvas)
for c in city_points.iterkeys():
x, y = city_points[c]
x, y = x-point_size[0]/2, y-point_size[1]/2
if c in wcities:
canvas.paste(point_blue, (x, y), point_blue)
canvas.save('russia-map-pinned.%s.v3.tif' % SPORT[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment