-conn = pgdb.connect(host=options.host,
- database=options.database,
- user=options.username)
-
-cursor = conn.cursor()
-
-###########
-# WARNING #
-###########
-#
-# Most GIS software, including PostGIS and the associated libraries,
-# store and manipulate GPS coordinates in (longitude, latitude) format
-# rather than (latitude, longitude) format.
-#
-
-query = """
-SELECT population_density
-FROM (sf1_blocks INNER JOIN tiger
- ON sf1_blocks.tiger_blkidfp00=tiger.blkidfp00)
-WHERE ST_Contains(tiger.the_geom,
- ST_SetSRID(ST_Point(%.6f, %.6f), 4269));
-""" % (coords.longitude, coords.latitude)
-
-cursor.execute(query)
-rows = cursor.fetchall()
-
-if len(rows) > 0:
- avg_density = rows[0][0]
+cdb = Census.Database(options.host,
+ options.database,
+ options.username,
+ options.srid)
+
+avg_density = cdb.find_average_population_density(coords)
+
+if (avg_density != None):