From 67ebbeeaad11d0c1c934c07692e932708aa3aecf Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Thu, 10 Sep 2009 00:57:39 -0400 Subject: [PATCH] Added an InvalidAreaError class. Caused the Block class to raise an InvalidAreaError when its total area is zero. --- src/SummaryFile1.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/SummaryFile1.py b/src/SummaryFile1.py index 50f23ad..3c82186 100644 --- a/src/SummaryFile1.py +++ b/src/SummaryFile1.py @@ -3,6 +3,8 @@ import os, GPS, inspect class RecordError(StandardError): pass +class InvalidAreaError(StandardError): + pass class GeoRecord: """ @@ -25,6 +27,7 @@ class 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) @@ -33,6 +36,9 @@ class Block: 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) @@ -75,6 +81,10 @@ class GeoRecordParser: block = Block(record) blocks.append(block) except ValueError: + # A value couldn't be converted to the appropriate type. + continue + except InvalidAreaError: + # Something is funny with the geometry. continue return blocks -- 2.44.2