]> gitweb.michael.orlitzky.com - dead/census-tools.git/blobdiff - src/SummaryFile1.py
Added the StringUtils module with the is_integer() function.
[dead/census-tools.git] / src / SummaryFile1.py
index 50f23ad0c96a83227137d60c7ff0fd2a4057efe8..0ad410d0dc4152b6642d96fb10c3b9647e466c3c 100644 (file)
@@ -1,15 +1,18 @@
-import os, GPS, inspect
+import os
+
+import GPS
+import StringUtils
+
 
 class RecordError(StandardError):
     pass
 
 
 class RecordError(StandardError):
     pass
 
-
 class GeoRecord:
     """
     This class wraps one record in an SF1 geo file.
     """
 
 class GeoRecord:
     """
     This class wraps one record in an SF1 geo file.
     """
 
-    MinimumLineLength = 400
+    MINIMUM_LINE_LENGTH = 400
 
 
 class Block:
 
 
 class Block:
@@ -25,6 +28,7 @@ class Block:
         # if the input string cannot be converted o the specified
         # type.
         self.block_number = int(geo_record.block)
         # if the input string cannot be converted o the specified
         # type.
         self.block_number = int(geo_record.block)
+        self.tract_number = int(geo_record.tract)
         self.population = int(geo_record.pop100)
         self.area_land = float(geo_record.arealand)
         self.area_water = float(geo_record.areawatr)
         self.population = int(geo_record.pop100)
         self.area_land = float(geo_record.arealand)
         self.area_water = float(geo_record.areawatr)
@@ -33,6 +37,9 @@ class Block:
         self.coordinates.latitude = float(geo_record.intptlat)
         self.coordinates.longitude = float(geo_record.intptlon)
 
         self.coordinates.latitude = float(geo_record.intptlat)
         self.coordinates.longitude = float(geo_record.intptlon)
 
+        if (self.total_area() == 0):
+            raise InvalidAreaError('A block may not have zero area.')
+        
 
     def total_area(self):
         return (self.area_land + self.area_water)
 
     def total_area(self):
         return (self.area_land + self.area_water)
@@ -75,6 +82,7 @@ class GeoRecordParser:
                 block = Block(record)
                 blocks.append(block)
             except ValueError:
                 block = Block(record)
                 blocks.append(block)
             except ValueError:
+                # A value couldn't be converted to the appropriate type.
                 continue
             
         return blocks
                 continue
             
         return blocks
@@ -88,8 +96,8 @@ class GeoRecordParser:
         allow the GeoRecord class to parse the data meaningfully and
         throw an error if something doesn't look right.
         """
         allow the GeoRecord class to parse the data meaningfully and
         throw an error if something doesn't look right.
         """
-        if (len(line) < GeoRecord.MinimumLineLength):
-            raise RecordError("The input line is too short. The SF1 specification requires a line length of %d characters; this line contains only %d characters" % (GeoRecord.MinimumLineLength, len(line)))
+        if (len(line) < GeoRecord.MINIMUM_LINE_LENGTH):
+            raise RecordError("The input line is too short. The SF1 specification requires a line length of %d characters; this line contains only %d characters" % (GeoRecord.MINIMUM_LINE_LENGTH, len(line)))
         
         record = GeoRecord()
 
         
         record = GeoRecord()