#!/usr/bin/python """ Find the total population contained within a geometric object. Our input is an OGC Well-Known Text[1] string. This string is used as part of a database query that finds the population contained within (i.e. 'underneath') the geometric object corresponding to the WKT string. [1] http://en.wikipedia.org/wiki/Well-known_text """ import sys import os import site # Basically, add '../src' to our path. # Needed for the imports that follow. site.addsitedir(os.path.dirname(os.path.abspath(sys.argv[0])) + '/../src') import Census import CLI import Configuration.Defaults import ExitCodes usage = '%prog [options] ' parser = CLI.default_option_parser(usage) # Use this module's docstring as the description. parser.description = __doc__ parser.add_option('-s', '--srid', type="int", help="SRID of the input geometry. Defaults to %s." % Configuration.Defaults.SRID, default=Configuration.Defaults.SRID) (options, args) = parser.parse_args() if len(args) < 1: print "\nERROR: You must supply a geometric object in Well-Known Text format.\n" parser.print_help() print '' # Print a newline. raise SystemExit(ExitCodes.NOT_ENOUGH_ARGS) cdb = Census.Database(options.host, options.database, options.username, options.srid) population = cdb.find_contained_population(args[0]) if (population != None): print population else: print 'Error: No rows returned.' raise SystemExit(ExitCodes.NO_RESULTS)