wm

Wang–Müller line generalization algorithm in PostGIS
Log | Files | Refs | README | LICENSE

gdr2pgsql (845B) - Raw


      1 #!/bin/bash
      2 set -euo pipefail
      3 
      4 dbzip=$(realpath -s "$1")
      5 tbl=$2
      6 filter=$3
      7 outfile=$4
      8 
      9 if [[ "$dbzip" =~ " " ]]; then
     10     echo "ERROR: $dbzip contains spaces"
     11     exit 1
     12 fi
     13 
     14 set -x
     15 
     16 gdbname=$(unzip -Z1 "$dbzip" | awk -Fgdb '/.gdb/{print $1"gdb";exit}')
     17 
     18 now=$(TZ=UTC date +"%FT%TZ")
     19 here=$(whoami)@$(hostname -f)
     20 
     21 mkdir -p ".tmp"
     22 ogr2ogr -skipfailures -f PGDump /dev/stdout -t_srs epsg:3857 \
     23     "/vsizip/$dbzip/$gdbname" -nln "src_$tbl" hidro_l | \
     24         awk "!/^INSERT/{print}; /^INSERT/&&/${filter}/{print;next}" | \
     25         bash ./db | \
     26         grep -v '^INSERT 0 1'
     27 
     28 bash db -f aggregate-rivers.sql -v "srctable=src_$tbl" -v "dsttable=$tbl"
     29 (
     30     echo "-- Generated at $now on $here";
     31     echo "-- Rivers: $filter";
     32     docker exec wm-mj pg_dump --clean -Uosm osm -t "$tbl" | tr -d '\r'
     33 ) > ".tmp/$outfile"
     34 mv ".tmp/$outfile" "$outfile"