-
Notifications
You must be signed in to change notification settings - Fork 1
/
initdb-postgis.sh
executable file
·67 lines (62 loc) · 1.98 KB
/
initdb-postgis.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh
set -e
# Perform all actions as user 'postgres'
export PGUSER=postgres
export PGDATA=$PGDATA
# Create the 'mg' template db
psql <<EOSQL
CREATE DATABASE mg;
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'mg';
EOSQL
# Populate 'template_postgis'
cd /usr/share/postgresql/$PG_MAJOR/contrib/postgis-$POSTGIS_MAJOR
psql --dbname mg < postgis.sql
psql --dbname mg < topology.sql
psql --dbname mg < spatial_ref_sys.sql
psql --dbname mg -c "CREATE EXTENSION hstore;"
psql -d mg -c "INSERT into spatial_ref_sys
(srid, auth_name, auth_srid, proj4text, srtext)
values
( 96700,
'sr-org',
6700,
'+proj=lcc +lat_1=17.5 +lat_2=29.5 +lat_0=12 +lon_0=-102 +x_0=2500000 +y_0=0 +a=6378137 +b=6378136.027241431 +units=m +no_defs ',
'PROJCS[\"unnamed\",
GEOGCS[\"WGS 84\",
DATUM[\"unknown\",
SPHEROID[\"WGS84\",6378137,6556752.3141]],
PRIMEM[\"Greenwich\",0],
UNIT[\"degree\",0.0174532925199433]],
PROJECTION[\"Lambert_Conformal_Conic_2SP\"],
PARAMETER[\"standard_parallel_1\",17.5],
PARAMETER[\"standard_parallel_2\",29.5],
PARAMETER[\"latitude_of_origin\",12],
PARAMETER[\"central_meridian\",-102],
PARAMETER[\"false_easting\",2500000],
PARAMETER[\"false_northing\",0]
]'
);"
cd /
mkdir scripts
for file in `ls -1 /data/*.shp`; do
table_name=''
file=`echo ${file}| sed 's/\/data\///'`
echo $file
case ${file:0:4} in
mge2) table_name='entidades'
;;
mglr) table_name='loc_rurales'
;;
mglu) table_name='loc_urbanas'
;;
mgm2) table_name='municipios'
;;
esac
script=`echo ${file}|sed 's/data//'`
shp2pgsql -I -WLATIN1 -s 96700 -g geom -p /data/${file} ${table_name} \
> scripts/${script}'_c.sql'
shp2pgsql -I -WLATIN1 -s 96700 -g geom -a /data/${file} ${table_name} \
> scripts/${script}'.sql'
psql -d mg -f scripts/${script}'_c.sql'
psql -d mg -f scripts/${script}'.sql'
done