| 1 | back to - [[https://it-dev.mpiwg-berlin.mpg.de/tracs/GIS/wiki/SystInst System Installation]] |
| 2 | == Import of CHGIS-Dataset into PostGIS == |
| 3 | |
| 4 | * copy the long code below into a file (like 'importscript.sh') and save it |
| 5 | * if necessary alter the variable-values |
| 6 | * open a terminal-window |
| 7 | * make the script-file executable: |
| 8 | {{{ |
| 9 | chmod 700 importscript.sh |
| 10 | }}} |
| 11 | * run it with |
| 12 | {{{ |
| 13 | ./importscript.sh |
| 14 | }}} |
| 15 | If the *.shp can not be imported, may be, the UTF-8 is not correctly saved: |
| 16 | Open the *.dbf with NeoOffice (choose Encoding UTF-8)and save again with UTF-8! |
| 17 | |
| 18 | {{{ |
| 19 | #! /bin/bash |
| 20 | |
| 21 | |
| 22 | #USAGE: $binpath/shp2pgsql [<options>] <shapefile> #[<schema>.]<table> |
| 23 | #OPTIONS: |
| 24 | # -s <$srid> Set the $srid field. If not specified it defaults to -1. |
| 25 | # (-d|a|c|p) These are mutually exclusive options: |
| 26 | # -d Drops the table, then recreates it and populates |
| 27 | # it with current shape file data. |
| 28 | # -a Appends shape file into current table, must be |
| 29 | # exactly the same table schema. |
| 30 | # -c Creates a new table and populates it, this is the |
| 31 | # default if you do not specify any options. |
| 32 | # -p Prepare mode, only creates the table. |
| 33 | # -g <geometry_column> Specify the name of the geometry column |
| 34 | # (mostly useful in append mode). |
| 35 | # -D Use postgresql dump format (defaults to sql insert statments. |
| 36 | # -k Keep postgresql identifiers case. |
| 37 | # -i Use int4 type for all integer dbf fields. |
| 38 | # -I Create a GiST index on the geometry column. |
| 39 | # -S Generate simple geometries instead of MULTI geometries. |
| 40 | # -w Use wkt format (for postgis-0.x support - drops M - drifts coordinates). |
| 41 | |
| 42 | # -W <$encoding> Specify the character $encoding of Shape's |
| 43 | # attribute column. (default : "ASCII") |
| 44 | # -N <policy> Specify NULL geometries handling policy (insert,skip,abort) |
| 45 | # -n Only import DBF file. |
| 46 | # -? Display this help screen |
| 47 | |
| 48 | # If the *.shp can not be imported, may be, the UTF-8 is not correctly saved: |
| 49 | # Open the *.dbf with NeoOffice (choose Encoding UTF-8)and save again with UTF-8! |
| 50 | |
| 51 | #_____________________ |
| 52 | # VARIABLE DEFINITIONS |
| 53 | |
| 54 | database=testdb |
| 55 | srid="2333" |
| 56 | encod="UTF-8" |
| 57 | binpath=/Developer/usr/local/pgsql/bin |
| 58 | dbpath=/Developer/usr/local/pgsql/data |
| 59 | datapath=/Users/fknauft/Projekt/rawdata |
| 60 | |
| 61 | #_____________________ |
| 62 | # |
| 63 | |
| 64 | su - postgres |
| 65 | |
| 66 | # restarting postgres |
| 67 | $binpath/pg_ctl restart -w -l $dbpath/logfile -D $dbpath -m i |
| 68 | |
| 69 | # dropping the old database |
| 70 | $binpath/dropdb $database |
| 71 | |
| 72 | # creating a new database |
| 73 | $binpath/createdb $database --encoding $encod |
| 74 | $binpath/createlang plpgsql $database |
| 75 | $binpath/psql -f $binpath/../share/lwpostgis.sql $database |
| 76 | |
| 77 | $binpath/shp2pgsql -s $srid -S -W $encod $datapath/v4_1820_lks_pgn_utf/v4_1820_lks_pgn_utf.shp public.v4_1820_lks_pgn_utf $database | $binpath/psql -d $database |
| 78 | |
| 79 | $binpath/shp2pgsql -s $srid -W $encod $datapath/v4_1820_rvr_lin_utf/v4_1820_rvr_lin_utf.shp public.v4_1820_rvr_lin_utf $database | $binpath/psql -d $database |
| 80 | |
| 81 | $binpath/shp2pgsql -s $srid -S -W $encod $datapath/v4_time_cnty_pts_utf/v4_time_cnty_pts_utf.shp public.v4_time_cnty_pts_utf $database | $binpath/psql -d $database |
| 82 | |
| 83 | $binpath/shp2pgsql -s $srid -W $encod $datapath/v4_time_pref_pgn_utf/v4_time_pref_pgn_utf.shp public.v4_time_pref_pgn_utf $database | $binpath/psql -d $database |
| 84 | |
| 85 | $binpath/shp2pgsql -s $srid -S -W $encod $datapath/v4_time_pref_pts_utf/v4_time_pref_pts_utf.shp public.v4_time_pref_pts_utf $database | $binpath/psql -d $database |
| 86 | |
| 87 | $binpath/shp2pgsql -s $srid -W $encod $datapath/v4_time_prov_pgn_utf/v4_time_prov_pgn_utf.shp public.v4_time_prov_pgn_utf $database | $binpath/psql -d $database |
| 88 | |
| 89 | $binpath/shp2pgsql -s $srid -S -W $encod $datapath/v4_time_prov_pts_utf/v4_time_prov_pts_utf.shp public.v4_time_prov_pts_utf $database | $binpath/psql -d $database |
| 90 | |
| 91 | $binpath/shp2pgsql -s $srid -W $encod $datapath/v4_time_reg_pgn_utf/v4_time_reg_pgn_utf.shp public.v4_time_reg_pgn_utf $database | $binpath/psql -d $database |
| 92 | |
| 93 | $binpath/shp2pgsql -s $srid -S -W $encod $datapath/v4_time_reg_pts_utf/v4_time_reg_pts_utf.shp public.v4_time_reg_pts_utf $database | $binpath/psql -d $database |
| 94 | |
| 95 | # VACUUM |
| 96 | $binpath/vacuumdb -d $database -z |
| 97 | }}} |