From 22f3773632026fb572770a9838eb1c7f01c5e394 Mon Sep 17 00:00:00 2001 From: Ed Chalstrey Date: Fri, 1 Apr 2022 14:28:46 +0100 Subject: [PATCH] create load coordinates script --- etl/load_coordinates.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 etl/load_coordinates.sh diff --git a/etl/load_coordinates.sh b/etl/load_coordinates.sh new file mode 100644 index 00000000..80c56193 --- /dev/null +++ b/etl/load_coordinates.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# Assign latitute and longitute to buildings with OpenTOID data +# - assume postgres connection details are set in the environment using PGUSER, PGHOST etc. + +: ${1?"Usage: $0 ./path/to/opentoid/dir"} + +opentoid_dir=$1 + +echo "Create a temporary table for coordinates..." +psql -c "CREATE TABLE open_toid ( + toid varchar, + version_number smallint, + version_date date, + source_product varchar, + easting float, + northing float, + latitute float, + longitude float +);" + +echo "Loading Open TOID CSV(s) to temporary table..." +find $opentoid_dir -type f -name '*.csv' \ +-printf "$opentoid_dir/%f\n" | \ +parallel \ +cat {} '|' psql -c "\"COPY open_toid ( toid, version_number, version_date, easting, northing ) FROM stdin WITH CSV HEADER;\"" + +# Convert the northing/easting coordinates to latitude/longitute with PostGIS +psql -c "update open_toid set the_geom=GeomFromText('POINT('||easting||' '||northing||')',27700);" +psql -c "update open_toid set longitude=st_x(st_transform(the_geom,4326)), latitude=st_y(st_transform(the_geom,4326));" + +# Update the buildings table with coordinates + + +# Delete the temporary table \ No newline at end of file