print >> sys.stderr,"######## indexing shapes ########" for line in sys.stdin: #( lng, lat ) = coord #NOTE:the input file must contain (lng,lat) values=line.replace("(","").replace(")","").replace("[","").replace("]","").strip().split(",") lng = float(values[0]) lat = float(values[1]) point = Point(float(lng), float(lat)) coords=grid_finder(lng,lat) found=False if coords not in grid: counter+=1 print >> sys.stderr,"not in grid:{},not in county:{},found{}".format(counter,in_grid_not_in_county,grid_counter) print >> sys.stderr,"{},{}: not in grid".format(lng,lat) continue for box in grid[coords]: if box.contains(point): if grid[coords][box][0].contains(point): e=tree() found=True grid_counter+=1 e["coords"]=(lng,lat) e["GEOID"]=grid[coords][box][1] e["centroid"]=(grid[coords][box][3],grid[coords][box][4]) e["county"]=grid[coords][box][2] print json.dumps(e) break #point found, no need to continue searching if not found: in_grid_not_in_county+=1 print >> sys.stderr,"######## DONE ########" print >> sys.stderr, "{} points outside of grid".format(counter) print >> sys.stderr, "{} points in grid but not in a county".format(in_grid_not_in_county)
values = line.replace("(", "").replace(")", "").replace("[", "").replace( "]", "").strip().split(",") lng = float(values[0]) lat = float(values[1]) point = Point(float(lng), float(lat)) coords = grid_finder(lng, lat) found = False if coords not in grid: counter += 1 print >> sys.stderr, "not in grid:{},not in county:{},found{}".format( counter, in_grid_not_in_county, grid_counter) print >> sys.stderr, "{},{}: not in grid".format(lng, lat) continue for box in grid[coords]: if box.contains(point): if grid[coords][box][0].contains(point): e = tree() found = True grid_counter += 1 e["coords"] = (lng, lat) e["GEOID"] = grid[coords][box][1] e["centroid"] = (grid[coords][box][3], grid[coords][box][4]) e["county"] = grid[coords][box][2] print json.dumps(e) break #point found, no need to continue searching if not found: in_grid_not_in_county += 1 print >> sys.stderr, "######## DONE ########" print >> sys.stderr, "{} points outside of grid".format(counter)
def find_in_boxes(boxes, point): for box, neighborhood in boxes: if box.contains(point): print "This is neighborhood", neighborhood.name return neighborhood