]>
gitweb.michael.orlitzky.com - dead/census-tools.git/blob - src/Census.py
8 This class wraps all of the operations that we'd like to perform
9 on the census database. Most of the utility scripts will just call
10 one or two methods from within this class.
13 def __init__(self
, _host
, _database
, _username
, _srid
):
14 self
.connection
= pgdb
.connect(host
=_host
,
21 self
.connection
.close()
24 def find_average_population_density(self
, coords
):
26 Find the average population density at a set of GPS coordinates.
28 cursor
= self
.connection
.cursor()
31 SELECT population_density
32 FROM (sf1_blocks INNER JOIN tiger
33 ON sf1_blocks.tiger_blkidfp00=tiger.blkidfp00)
34 WHERE ST_Contains(tiger.the_geom,
35 ST_SetSRID(ST_Point(%.6f, %.6f), %d));
38 sql_params
= (coords
.longitude
, coords
.latitude
, self
.srid
)
39 cursor
.execute(query
, sql_params
)
40 rows
= cursor
.fetchall()