Exemplo n.º 1
0
def cartogram(args):
    C = Cartogram()
    C.generate(args.map, args.attr, args.data, args.key, args.val)
Exemplo n.º 2
0
def cartogram(args):
    C = Cartogram()
    C.generate(args.map, args.attr, args.data, args.key, args.val)
Exemplo n.º 3
0
def main():
    start = time.time()

    from errors import KartographError

    if len(sys.argv) < 3:
        print "try: kartograph svg map-config.yaml"
        sys.exit(1)

    command = sys.argv[1]

    if command in ("generate", "kml", "svg"):

        cfg = {}
        output = None
        opt_src = None
        opts, args = getopt.getopt(sys.argv[2:], 'c:o:', ['config=', 'output='])
        for o, a in opts:
            if o in ('-c', '--config'):
                opt_src = a
            elif o in ('-o', '--output'):
                output = a

        # check and load map configuration
        if os.path.exists(opt_src):
            t = open(opt_src, 'r').read()
            if opt_src[-5:].lower() == '.json':
                cfg = json.loads(t)
            elif opt_src[-5:].lower() == '.yaml':
                import yaml
                cfg = yaml.load(t)
            else:
                raise KartographError('supported config formats are .json and .yaml')
        else:
            raise KartographError('configuration not found')

        K = Kartograph()

        try:
            if command == "kml":
                K.generate_kml(cfg, output)
            else:
                K.generate(cfg, output)
        except KartographError as e:
            print e

        elapsed = (time.time() - start)

        print 'execution time: %.4f secs' % elapsed
        sys.exit(0)

    elif command == "cartogram":

        map = sys.argv[2]
        attr = sys.argv[3]
        data = sys.argv[4]
        key = sys.argv[5]
        val = sys.argv[6]

        C = Cartogram()
        C.generate(map, attr, data, key, val)