#!/bin/env python
"""
rasterstats

Given a vector and a raster dataset, run zonal stats and output a csv to stdout

Usage:
  rasterstats VECTOR RASTER
  rasterstats VECTOR RASTER --categorical
  rasterstats (-h | --help)
  rasterstats --version

Options:
  -h --help     Show this screen.
  --version     Show version.
"""
import sys
from docopt import docopt
from rasterstats import raster_stats, stats_to_csv


if __name__ == '__main__':
    opt = docopt(__doc__, version="0.3") # TODO get from setup or other common 
    if opt['VECTOR'] == "-":
        # use stdin
        opt['VECTOR'] = sys.stdin.readlines()[-1].strip()
    args = []
    kwargs = {}
    print opt
    import ipdb; ipdb.set_trace()
    if opt['--categorical']:
        stats = raster_stats(opt['VECTOR'], opt['RASTER'],
                             stats="minority majority count unique",
                             categorical=True)
    else:
        stats = raster_stats(opt['VECTOR'], opt['RASTER'], stats="*")
    print stats_to_csv(stats)

