back to - [[https://it-dev.mpiwg-berlin.mpg.de/tracs/GIS/wiki/SystInst System Installation]] == Import of CHGIS-Dataset into PostGIS == * copy the long code below into a file (like 'importscript.sh') and save it * if necessary alter the variable-values * open a terminal-window * make the script-file executable: {{{ chmod 700 importscript.sh }}} * run it with {{{ ./importscript.sh }}} If the *.shp can not be imported, may be, the UTF-8 is not correctly saved: Open the *.dbf with NeoOffice (choose Encoding UTF-8)and save again with UTF-8! {{{ #! /bin/bash #USAGE: $binpath/shp2pgsql [] #[.] #OPTIONS: # -s <$srid> Set the $srid field. If not specified it defaults to -1. # (-d|a|c|p) These are mutually exclusive options: # -d Drops the table, then recreates it and populates # it with current shape file data. # -a Appends shape file into current table, must be # exactly the same table schema. # -c Creates a new table and populates it, this is the # default if you do not specify any options. # -p Prepare mode, only creates the table. # -g Specify the name of the geometry column # (mostly useful in append mode). # -D Use postgresql dump format (defaults to sql insert statments. # -k Keep postgresql identifiers case. # -i Use int4 type for all integer dbf fields. # -I Create a GiST index on the geometry column. # -S Generate simple geometries instead of MULTI geometries. # -w Use wkt format (for postgis-0.x support - drops M - drifts coordinates). # -W <$encoding> Specify the character $encoding of Shape's # attribute column. (default : "ASCII") # -N Specify NULL geometries handling policy (insert,skip,abort) # -n Only import DBF file. # -? Display this help screen # If the *.shp can not be imported, may be, the UTF-8 is not correctly saved: # Open the *.dbf with NeoOffice (choose Encoding UTF-8)and save again with UTF-8! #_____________________ # VARIABLE DEFINITIONS database=testdb srid="2333" encod="UTF-8" binpath=/Developer/usr/local/pgsql/bin dbpath=/Developer/usr/local/pgsql/data datapath=/Users/fknauft/Projekt/rawdata #_____________________ # su - postgres # restarting postgres $binpath/pg_ctl restart -w -l $dbpath/logfile -D $dbpath -m i # dropping the old database $binpath/dropdb $database # creating a new database $binpath/createdb $database --encoding $encod $binpath/createlang plpgsql $database $binpath/psql -f $binpath/../share/lwpostgis.sql $database $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 $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 $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 $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 $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 $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 $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 $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 $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 # VACUUM $binpath/vacuumdb -d $database -z }}}