]> gitweb.michael.orlitzky.com - dead/census-tools.git/blobdiff - src/Census.py
Added unit tests for the Census.Database class.
[dead/census-tools.git] / src / Census.py
index ae4d28d0de1a72bd631021cb6da270193850d991..a69ff58b9cb68fea0e8c398d5fce289f7954a87e 100644 (file)
@@ -1,6 +1,7 @@
 import pgdb
 
 import GPS
+import SummaryFile1
 
 
 class Database:
@@ -20,7 +21,7 @@ class Database:
     def __del__(self):
         self.connection.close()
 
-        
+
     def find_average_population_density(self, coords):
         """
         Find the average population density at a set of GPS coordinates.
@@ -110,3 +111,28 @@ class Database:
         else:
             return None
 
+
+
+    def get_block_geometry_as_wkt(self, blkidfp00):
+        """
+        Find the geometry of a (uniquely-identified) block, in
+        Well-Known Text format.
+        """
+        cursor = self.connection.cursor()
+
+        query = """
+        SELECT ST_AsText(tiger.the_geom)
+        FROM tiger
+        WHERE tiger.blkidfp00 = %s;
+        """
+        sql_params = (blkidfp00,)
+
+        cursor.execute(query, sql_params)
+        rows = cursor.fetchall()
+        cursor.close()
+
+        if len(rows) > 0:
+            return rows[0][0]
+        else:
+            return None
+