# # script to determine which communities are located in study region # 31 October 2006 # def community_in_extent(filename,extent,zone,fid_out): fid = open(filename) lines = fid.readlines() fid.close() line1 = lines[0] line11 = line1.split(',') for i in range(len(line11)): if line11[i].strip('\n').strip(' ') == 'LATITUDE': lat_index = i if line11[i].strip('\n').strip(' ') == 'LONGITUDE': lon_index = i if line11[i].strip('\n').strip(' ') == 'COMMUNITY': name_index = i from anuga.coordinate_transforms.redfearn import convert_from_latlon_to_utm from anuga.utilities.polygon import plot_polygons, is_inside_polygon for line in lines[1:]: fields = line.split(',') point, zone1 = convert_from_latlon_to_utm(latitudes=[fields[lat_index]],\ longitudes=[fields[lon_index]]) if zone1 == zone: v = is_inside_polygon(point,extent,verbose=False) if v == True: p = point[0] s = '%s, %.2f, %.2f\n' %(fields[name_index], p[0], p[1]) fid_out.write(s) return import project filename = project.community_filename filename_out = project.community_perth fid_out = open(filename_out, 'w') extent = project.polyAll zone = 50 community_in_extent(filename,extent,zone,fid_out)