# run function find_zip with lon and lat of current row as a point and the index of the last found point result = Zip_Backfill.find_zip(Point(float(s_point[0]), float(s_point[1])), current_inx, sorted_key, zips) # set current_inx to the index of the last point found current_inx = result[1] # if zcta zip is same as on file if result[0] == s_point[7]: s_point[8] = "same" # if no zcta zip is found elif result[0] == "None": s_point[8] = "None" # if zcta is not the same as on file write in found zip else: s_point[8] = result[0] output.write(",".join(s_point) + "\n") output.close() if __name__ == "__main__": import argparse # command line parser parser = argparse.ArgumentParser(description="Backfills zip code to single file") parser.add_argument("input", help="OpenAddresses file to backfill from") parser.add_argument("output", help="file to to backfill to") parser.add_argument("shape_file", help="a census ZCTA shape file") args = parser.parse_args() zips_load = Zip_Backfill.import_zip(args.shape_file) write_openaddresses_test(args.input, args.output, zips_load[0], zips_load[1])
parser.add_argument('-o', '--openaddresses', help = 'check against zips in openaddresses, use a file with zips as input', action = 'store_true') args = parser.parse_args() #check that a flag is picked #create temp file for storing data temp_rand = random.randint(1000000,9999999) print 'picks rows' #open temp file and write in random rows pick_rand.write_rows(args.input, temp_rand, args.number) print 'load poly' #load shape file zips_load = Zip_Backfill.import_zip(args.shape_file) if args.openaddresses: print 'run test' Self_Check.write_openaddresses_test(temp_rand, args.output, zips_load[0], zips_load[1]) else: temp_backfill = random.randint(10000000,99999999) print 'backfill' Zip_Backfill.write_zip(temp_rand, temp_backfill, zips_load[0], zips_load[1])