Guest User

Untitled

a guest
Oct 28th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # copies a geopackage or ESRI FileGDB to a given schema on a postgresql database
  4.  
  5. # ./push2db schema_name "PG:dbname=dbname host=host port=port user=user password=password" filename.gpkg
  6. #
  7. #./push2db cartwheel "PG:dbname=jpsgis host=localhost port=5432 user=rhys password=rhys" ~/Public/electricgis_nkredsqlentclu.gdb.zip
  8.  
  9. SCHEMA=$1
  10. DB_URL=$2
  11. FILENM=$3
  12. SRID=$4
  13.  
  14. function pushtodb {
  15.  
  16. SCHEMA=$1
  17. DB_URL="$2"
  18. FILENM=$3
  19. INTBL=$4
  20.  
  21. ogr2ogr -PROGRESS \
  22. --config PG_USE_COPY YES \
  23. -f "Postgresql" "$DB_URL" \
  24. $FILENM \
  25. -lco UNLOGGED=YES \
  26. -lco SCHEMA=$SCHEMA \
  27. -lco GEOMETRY_NAME=g \
  28. -lco LAUNDER=NO \
  29. $INTBL
  30.  
  31. }
  32.  
  33. echo "***************** Creating schema $1;"
  34. ogrinfo "$2" -sql "CREATE SCHEMA $1;"
  35.  
  36.  
  37. for i in $( ogrinfo $FILENM \
  38. | grep '^[0-9]' \
  39. | sed s/[0-9]//g \
  40. | sed s/://g \
  41. | sed s/\\s// \
  42. | sed s/\\s.*// \
  43. | while read litmus; do echo "$litmus"; done ) ;
  44. do
  45. echo item: $i;
  46. pushtodb $1 "$2" $3 $i
  47. done
Add Comment
Please, Sign In to add comment