total_points = (steps_x + 1)*(steps_y + 1) c = 0 added = 0 boundaries = get_country_boundaries(countries) for i_x in range(steps_x + 1): for i_y in range(steps_y + 1): point = (min_x + i_x*step, min_y + i_y*step) #Check if point belongs to projection try: proj(point[0], point[1], inverse=True, errcheck=True) #check point is in a country found = locate(point, countries, boundaries, projected=True) if found: lookup[json.dumps(point)] = found added += 1 except RuntimeError: pass c += 1 if not c % 10000: print "processed %s of %s (%s added) in %s" % (c, total_points, added, round(time.time() - start, 1)) return lookup if __name__ == "__main__": countries = Geo.countries() lookup = generate_lookup(countries) datapath = os.path.join(settings.DATA_FOLDER, "country-lookup.json") g = open(datapath, 'w') g.write(json.dumps(lookup)) g.close()