2022-04-01 09:28:46 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2022-04-04 05:38:58 -04:00
|
|
|
# Assign latitude and longitude to buildings with OpenTOID data
|
2022-04-01 09:28:46 -04:00
|
|
|
# - assume postgres connection details are set in the environment using PGUSER, PGHOST etc.
|
|
|
|
|
|
|
|
: ${1?"Usage: $0 ./path/to/opentoid/dir"}
|
|
|
|
|
|
|
|
opentoid_dir=$1
|
|
|
|
|
2022-04-04 09:18:23 -04:00
|
|
|
echo "Creating table for open_toid coordinates..."
|
2022-04-01 09:28:46 -04:00
|
|
|
psql -c "CREATE TABLE open_toid (
|
|
|
|
toid varchar,
|
2022-04-04 08:35:26 -04:00
|
|
|
version_number float,
|
2022-04-01 09:28:46 -04:00
|
|
|
version_date date,
|
|
|
|
source_product varchar,
|
|
|
|
easting float,
|
|
|
|
northing float,
|
2022-04-01 11:50:15 -04:00
|
|
|
longitude float,
|
2022-04-04 08:59:40 -04:00
|
|
|
latitude float
|
2022-04-01 09:28:46 -04:00
|
|
|
);"
|
|
|
|
|
|
|
|
echo "Loading Open TOID CSV(s) to temporary table..."
|
2022-04-04 06:12:12 -04:00
|
|
|
find $opentoid_dir -type f -name '*_converted.csv' \
|
2022-04-01 09:28:46 -04:00
|
|
|
-printf "$opentoid_dir/%f\n" | \
|
|
|
|
parallel \
|
2022-04-04 08:59:40 -04:00
|
|
|
cat {} '|' psql -c "\"COPY open_toid ( toid, version_number, version_date, source_product, easting, northing, longitude, latitude ) FROM stdin WITH CSV HEADER;\""
|
2022-04-01 09:28:46 -04:00
|
|
|
|
2022-04-04 06:42:27 -04:00
|
|
|
echo "Updating the buildings table with coordinates..."
|
|
|
|
psql -c "UPDATE buildings
|
2022-04-04 08:59:40 -04:00
|
|
|
SET location_latitude = open_toid.latitude,
|
2022-04-04 06:42:27 -04:00
|
|
|
location_longitude = open_toid.longitude
|
|
|
|
FROM open_toid
|
2022-04-04 08:48:08 -04:00
|
|
|
WHERE open_toid.toid = buildings.ref_toid
|
2022-04-04 09:18:23 -04:00
|
|
|
;"
|