diff --git a/etl/convert_opentoid_bng_latlon.py b/etl/convert_opentoid_bng_latlon.py new file mode 100644 index 00000000..ccf874c3 --- /dev/null +++ b/etl/convert_opentoid_bng_latlon.py @@ -0,0 +1,30 @@ +"""Convert BNG values in OpenTOID data to latitude/longitude""" +import csv +import glob +import os +import sys +from convertbng.util import convert_lonlat +from pandas import read_csv + + +csv.field_size_limit(sys.maxsize) + + +def main(opentoid_path): + ot_paths = sorted(glob.glob(os.path.join(opentoid_path, "*.csv"))) + for ot_path in ot_paths: + convert_opentoid_coordinates(ot_path) + + +def convert_opentoid_coordinates(ot_path): + """Overwrite the input csv, adding the longitute/latitude from eastings/northings""" + ot_data = read_csv(ot_path) + ot_data['longitude'], ot_data['latitude'] = convert_lonlat(ot_data['EASTING'], ot_data['NORTHING']) + ot_data.to_csv(ot_path) + + +if __name__ == '__main__': + if len(sys.argv) != 2: + print("Usage: convert_opentoid_bng_latlon.py ./path/to/opentoid/dir") + exit(-1) + main(sys.argv[1]) diff --git a/etl/requirements.txt b/etl/requirements.txt index 55188359..2623c138 100644 --- a/etl/requirements.txt +++ b/etl/requirements.txt @@ -5,3 +5,4 @@ psycopg2==2.7.5 shapely==1.7 retrying==1.3.3 requests==2.23.0 +convertbng==0.6.37