import json import sys from globe import pyglobe from random import randint if __name__ == '__main__': from optparse import OptionParser parser = OptionParser() parser.add_option("-c","--country",dest="country",type="string",help="center on the specified country") parser.add_option("-o","--outputpath",dest="outpath",help="specify output file path") (options,args) = parser.parse_args() latlong = (0,0) data = open("countries.json","r+") countries = [] for line in data: countries.append(json.loads(line.strip())) for country in countries: lat = float(country["info"]["LAT"]) lon = float(country["info"]["LON"]) name = country["info"]["NAME"] if options.country and options.country == name: latlong = (lat,lon) g = pyglobe(latlong[0],latlong[1],400,"World Map (centered on %.0f lat, %.0f lon)"%latlong) cid = 1 for country in countries: classname = "c"+str(cid) parts = country["parts"] name = country["info"]["NAME"] fill=(128+randint(0,127),128+randint(0,127),128+randint(0,127)) for part in parts: l = [] points = parts[part] for point in points: l.append((point[1],point[0])) g.addRegion(l,fill,classname) g.addTooltip(name,classname) cid += 1 g.render(options.outpath)