X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FSummaryFile1.py;h=18164ed898609e1b429e99a7890a047cf4472346;hb=a288d4500730745bdd483c33c02411b9237b4a9f;hp=bfc62582f2d80db6c9b96f6d57b8386838d4e065;hpb=f6b26952ca47d6a3740ef244ce030e08be56679f;p=dead%2Fcensus-tools.git diff --git a/src/SummaryFile1.py b/src/SummaryFile1.py index bfc6258..18164ed 100644 --- a/src/SummaryFile1.py +++ b/src/SummaryFile1.py @@ -45,12 +45,22 @@ class Block: self.arealand = float(geo_record.arealand) self.areawatr = float(geo_record.areawatr) + # Both latitude and longitude are given to six digits of + # precision (i.e. after the decimal point). But, there are no + # decimal points in the intptlon/intptlat fields, so we need + # to add them. + # + # By default, the coordinates will be parsed as integers. For + # example, +12345678 will be parsed as 12345678.0. So, we need + # to "move" that decimal point 6 places to the left. We know + # how to do that. + # self.coordinates = GPS.Coordinates() - self.coordinates.latitude = float(geo_record.intptlat) - self.coordinates.longitude = float(geo_record.intptlon) + self.coordinates.latitude = (float(geo_record.intptlat) / (10**6)) + self.coordinates.longitude = (float(geo_record.intptlon) / (10**6)) - def tiger_blkidfp00(self): + def blkidfp00(self): # From the Tiger/Line shapefile documentation: # # Current block identifier; a concatenation of Census 2000 @@ -400,32 +410,3 @@ class GeoRecordParser: return record - - - -def FindClosestBlock(blocks, target_coords): - """ - Find the closest block (from within blocks) to the GPS - coordinates given by target_coords. - """ - - # Empty by default. Hopefully we're passed some blocks. - closest_block = None - min_distance = 999999999.0 # Don't look at me like that. - - for block in blocks: - this_distance = GPS.CalculateDistance(target_coords, block.coordinates) - if (this_distance < min_distance): - closest_block = block - min_distance = this_distance - - return closest_block - - - -def FindAveragePopulationDensity(coords, geo_file_path): - grp = GeoRecordParser() - blocks = grp.parse_blocks(geo_file_path) - closest_block = FindClosestBlock(blocks, coords) - - return closest_block.population_density()