add echos to load geometries

This commit is contained in:
Ed Chalstrey 2022-03-29 14:48:27 +01:00
parent 0e01971b4a
commit 2163dc5812

View File

@ -1,27 +1,25 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#
# Load geometries from GeoJSON to Postgres # Load geometries from GeoJSON to Postgres
# - assume postgres connection details are set in the environment using PGUSER, PGHOST etc. # - assume postgres connection details are set in the environment using PGUSER, PGHOST etc.
#
: ${1?"Usage: $0 ./path/to/mastermap/dir"} : ${1?"Usage: $0 ./path/to/mastermap/dir"}
mastermap_dir=$1 mastermap_dir=$1
#
# Create 'geometry' record with # Create 'geometry' record with
# id: <polygon-guid>, # id: <polygon-guid>,
# source_id: <toid>, # source_id: <toid>,
# geom: <geom> # geom: <geom>
#
echo "Copy geometries to db..."
find $mastermap_dir -type f -name '*.3857.csv' \ find $mastermap_dir -type f -name '*.3857.csv' \
-printf "$mastermap_dir/%f\n" | \ -printf "$mastermap_dir/%f\n" | \
parallel \ parallel \
cat {} '|' psql -c "\"COPY geometries ( geometry_geom, source_id ) FROM stdin WITH CSV HEADER;\"" cat {} '|' psql -c "\"COPY geometries ( geometry_geom, source_id ) FROM stdin WITH CSV HEADER;\""
#
# Delete any duplicated geometries (by TOID) # Delete any duplicated geometries (by TOID)
# echo "Delete duplicate geometries..."
psql -c "DELETE FROM geometries a USING ( psql -c "DELETE FROM geometries a USING (
SELECT MIN(ctid) as ctid, source_id SELECT MIN(ctid) as ctid, source_id
FROM geometries FROM geometries