]>
gitweb.michael.orlitzky.com - dead/census-tools.git/blob - bin/wkt2pop
4 Find the total population contained within a geometric object.
8 Our input is an OGC Well-Known Text[1] string. This string is used as
9 part of a database query that finds the population contained within
10 (i.e. 'underneath') the geometric object corresponding to the WKT
13 [1] http://en.wikipedia.org/wiki/Well-known_text
19 from optparse
import OptionParser
21 # Basically, add '../src' to our path.
22 # Needed for the imports that follow.
23 site
.addsitedir(os
.path
.dirname(os
.path
.abspath(sys
.argv
[0])) + '/../src')
26 import Configuration
.Defaults
29 usage
= '%prog [options] <well-known text representation>'
31 # -h (help) Conflicts with -h HOSTNAME
32 parser
= OptionParser(usage
=usage
, add_help_option
= False)
34 # Use this module's docstring as the description.
35 parser
.description
= __doc__
.strip()
37 parser
.add_option('-h',
39 help='The hostname/address where the database is located.',
40 default
=Configuration
.Defaults
.DATABASE_HOST
)
42 parser
.add_option('-d',
44 help='The database in which the population data are stored.',
45 default
=Configuration
.Defaults
.DATABASE_NAME
)
47 parser
.add_option('-U',
49 help='The username who has access to the database.',
50 default
=Configuration
.Defaults
.DATABASE_USERNAME
)
52 parser
.add_option('-s',
55 help="SRID of the input geometry. Defaults to %s." % Configuration
.Defaults
.SRID
,
56 default
=Configuration
.Defaults
.SRID
)
59 (options
, args
) = parser
.parse_args()
62 print "\nERROR: You must supply a geometric object in Well-Known Text format.\n"
64 print '' # Print a newline.
65 raise SystemExit(ExitCodes
.NOT_ENOUGH_ARGS
)
68 cdb
= Census
.Database(options
.host
,
73 population
= cdb
.find_contained_population(args
[0])
75 if (population
!= None):
78 print 'Error: No rows returned.'
79 raise SystemExit(ExitCodes
.NO_RESULTS
)