def postcodes_to_points(csv_file): postcodes_not_listed = [] postcodes = {} reader = csv.reader(csv_file) for row in reader: try: lat, lng = grid_to_ll(float(row[2]), float(row[3])) except: warn("Postcode %s not given a location, using a nearby value" % row[0]) yield [row[0], Point(lat, lng)]
def OSGB36GridRefToETRS89(mapRef): if len(mapRef) < 4: raise ValueError("Map ref too short") if len(mapRef) % 2 == 1: six.print_(ValueError("Unexpected input length")) coordLen = int((len(mapRef) - 2) / 2) code = mapRef[:2] east = int(mapRef[2:2 + coordLen]) * pow(10, 5 - coordLen) nrth = int(mapRef[2 + coordLen:]) * pow(10, 5 - coordLen) x1, y1 = parse_grid(code, east, nrth) (x, y, h) = OSGB36_to_ETRS89(x1, y1) (gla, glo) = grid_to_ll(x, y) return (gla, glo)
def OSGB36GridRefToETRS89(mapRef): if len(mapRef) < 4: raise ValueError("Map ref too short") if len(mapRef) % 2 == 1: six.print_(ValueError("Unexpected input length")) coordLen = int((len(mapRef) - 2) / 2) code = mapRef[:2] east = int(mapRef[2:2+coordLen])*pow(10,5-coordLen) nrth = int(mapRef[2+coordLen:])*pow(10,5-coordLen) x1, y1 = parse_grid(code, east, nrth) (x,y,h) = OSGB36_to_ETRS89 (x1, y1) (gla, glo) = grid_to_ll(x, y) return (gla, glo)
def _transform_points(points): return [grid_to_ll(*point) for point in points]
def test_grid_to_ll(): x = 614199.522 y = 159979.837 (gla, glo) = grid_to_ll(x, y) assert_almost_equal(gla, 51.297880, places=6) assert_almost_equal(glo, 1.072628, places=6)