2022-04-01 11:37:40 -04:00
|
|
|
"""Convert BNG values in OpenTOID data to latitude/longitude"""
|
|
|
|
import csv
|
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import sys
|
2022-04-04 04:36:41 -04:00
|
|
|
from convertbng.cutil import convert_lonlat
|
2022-04-01 11:37:40 -04:00
|
|
|
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"""
|
2022-04-04 04:56:51 -04:00
|
|
|
output_path = str(ot_path).replace(".csv", "_converted.csv")
|
2022-04-01 11:37:40 -04:00
|
|
|
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])
|