colouring-montreal/etl/load_coordinates.sh

41 lines
1.4 KiB
Bash
Raw Normal View History

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-01 11:50:15 -04:00
echo "Converting OSGB36 Eastings and Northings to WGS84 longitude and latitude coordinates..."
python convert_opentoid_bng_latlon.py $opentoid_dir
echo "Creating a temporary table for coordinates..."
2022-04-01 09:28:46 -04:00
psql -c "CREATE TABLE open_toid (
toid varchar,
version_number smallint,
version_date date,
source_product varchar,
easting float,
northing float,
2022-04-01 11:50:15 -04:00
longitude float,
latitute float
2022-04-01 09:28:46 -04:00
);"
echo "Loading Open TOID CSV(s) to temporary table..."
find $opentoid_dir -type f -name '*.csv' \
-printf "$opentoid_dir/%f\n" | \
parallel \
2022-04-01 11:50:15 -04:00
cat {} '|' psql -c "\"COPY open_toid ( toid, version_number, version_date, source_product, easting, northing, longitude, latitute ) FROM stdin WITH CSV HEADER;\""
2022-04-01 09:28:46 -04:00
# Convert the northing/easting coordinates to latitude/longitute with PostGIS
2022-04-01 11:50:15 -04:00
# psql -c "select AddGeometryColumn( 'public', 'open_toid', 'the_geom', 27700, 'POINT', 2);"
# 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));"
2022-04-01 09:28:46 -04:00
# Update the buildings table with coordinates
2022-04-01 09:56:58 -04:00
# psql -c ""
2022-04-01 09:28:46 -04:00
2022-04-01 09:56:58 -04:00
# Delete the temporary table
# psql -c "DROP TABLE open_toid;"