forked from oscarfonts/catastro2postgis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
catastro2postgis.sh
executable file
·80 lines (64 loc) · 2.24 KB
/
catastro2postgis.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
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
# Params
dbname=catastro
dbuser=postgres
s_srs=23031
grid="./ntv2/peninsula.gsb"
datadir=SantaEugeniaDeBerga/
# Crear base de datos
echo Creando base de datos $dbname con propietario $dbuser
psql -d postgres -U $dbuser -f sql/create_db.sql -v owner=$dbuser -v database=$dbname
# Diccionarios
echo Creando diccionarios
psql -d $dbname -U $dbuser -f sql/dict.sql
for file in dict/*.csv
do
table=`basename $file .csv`
psql -d $dbname -U $dbuser -c "COPY ${table} FROM '${PWD}/${file}' WITH DELIMITER ',' CSV HEADER"
done
# Shapefiles
for zipfile in ${datadir}*.zip
do
folder=`basename $zipfile .zip`
echo Descomprimiendo cartografia ${folder}
# Unzip twice to tmp
mkdir -p ${datadir}tmp/${folder}
unzip -qo "$zipfile" -d ${datadir}tmp/${folder}
for layerzip in ${datadir}tmp/${folder}/*.zip
do
unzip -qo "$layerzip" -d ${datadir}tmp/${folder}
rm $layerzip
done
# Reproject to EPSG:4326
echo Reproyectando ${folder}
ogr2ogr -overwrite -s_srs "+init=epsg:$s_srs +nadgrids=${grid} +wktext" -t_srs EPSG:4326 ${datadir}${folder} ${datadir}tmp/${folder}
for shapefile in ${datadir}${folder}/*.dbf
do
table=`basename $shapefile .dbf`
shp2pgsql -p -s 4326 $shapefile $table | psql -d $dbname -U $dbuser > /dev/null
shp2pgsql -W ISO-8859-1 -a -s 4326 $shapefile $table | psql -d $dbname -U $dbuser > /dev/null
done
done
# Datos alfanumericos (.cat)
./catstruct2sql.py | psql -d $dbname -U $dbuser
for gzfile in ${datadir}*.gz
do
filename=`basename $gzfile .gz`
echo Descomprimiendo datos alfanumericos ${filename}
gunzip -c "$gzfile" > ${datadir}tmp/${filename}
iconv -f ISO-8859-1 -t UTF-8 ${datadir}tmp/${filename} -o ${datadir}${filename}
dirname=`basename $filename .CAT`
mkdir ${datadir}$dirname
./cat2csv.py ${datadir}${filename} ${datadir}${dirname}
for csvfile in ${datadir}${dirname}/*.csv
do
table=`basename $csvfile .csv`
psql -d $dbname -U $dbuser -c "COPY ${table} FROM '${PWD}/${csvfile}' WITH DELIMITER ',' CSV HEADER"
done
done
# Calles & Vistas
echo Creando vistas
psql -d $dbname -U $dbuser -f sql/calles.sql
psql -d $dbname -U $dbuser -f sql/views.sql
# Limpieza
rm -R ${datadir}/tmp