Last active
August 29, 2015 14:10
-
-
Save george-silva/787861408555572ad100 to your computer and use it in GitHub Desktop.
Main script file and supporting scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SERVIDOR=$1 | |
PORTA=$2 | |
BANCO_DADOS=$3 | |
USUARIO=$4 | |
SENHA=$5 | |
CAMINHO_SAIDA=$6 | |
NOME_TABELA=$7 | |
NOME_VIEW=$8 | |
LAYER_TYPE=$9 | |
ogr2ogr -overwrite -nlt $LAYER_TYPE -nln $NOME_TABELA -sql "SELECT * FROM $NOME_VIEW" -f "FileGDB" $CAMINHO_SAIDA/exportacao.gdb PG:"host=$SERVIDOR port=$PORTA dbname='$BANCO_DADOS' user='$USUARIO' password='$SENHA'" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SERVIDOR=$1 | |
PORTA=$2 | |
BANCO_DADOS=$3 | |
USUARIO=$4 | |
SENHA=$5 | |
CAMINHO_SAIDA=$6 | |
NOME_TABELA=$7 | |
NOME_VIEW=$8 | |
cd $CAMINHO_SAIDA | |
pgsql2shp -f $NOME_TABELA"_exportar.shp" -h $SERVIDOR -p $PORTA -u $USUARIO -k $BANCO_DADOS $NOME_VIEW | |
ogr2ogr $NOME_TABELA"_exportar_iso.shp" $NOME_TABELA"_exportar.shp" -overwrite -lco ENCODING=UTF-8 | |
zip $NOME_TABELA".zip" $NOME_TABELA"_exportar_iso.shp" $NOME_TABELA"_exportar_iso.shx" $NOME_TABELA"_exportar_iso.prj" $NOME_TABELA"_exportar_iso.cpg" $NOME_TABELA"_exportar_iso.dbf" | |
rm -rf *.shp *.shx *.dbf *.prj *.cpg | |
cd - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# forma de uso ./exportar <host> <porta> <nome_do_banco_de_dados> <usuario> <senha> <caminho> <formato> | |
# este script depende de: lib32z1 lib32ncurses5 lib32bz2-1.0 e filegdbapi | |
export SHAPE_ENCODING="ISO-8859-1" | |
SERVIDOR=$1 | |
PORTA=$2 | |
BANCO_DADOS=$3 | |
USUARIO=$4 | |
SENHA=$5 | |
CAMINHO_SAIDA=$6 | |
FORMATO=$7 | |
SEPARADOR="--------------------------------------------------" | |
echo "configurando postgresql" | |
set PGPASSWORD=$5 | |
set PGCLIENTENCODING=latin1 | |
echo "listando camadas de interesse" | |
psql -h $SERVIDOR -p $PORTA -U $USUARIO -d $BANCO_DADOS -P 'format=unaligned' --field-separator=";" -t -c "SELECT nome_tabela, nome_view, gc.type FROM camada, geometry_columns gc WHERE exportar IS TRUE AND nome_view IS NOT NULL AND nome_tabela = f_table_name" > exportar.temp | |
IFS=$'\n' | |
echo $SEPARADOR | |
echo "iniciando processamento" | |
echo $SEPARADOR | |
for linha in `cat ./exportar.temp` | |
do | |
IFS=\; | |
read -a CAMPOS <<< "$linha" | |
NOME_TABELA=${CAMPOS[0]} | |
NOME_VIEW=${CAMPOS[1]} | |
LAYER_TYPE=${CAMPOS[2]} | |
IFS=$'\n' | |
echo "processando "$NOME_TABELA | |
CONTADOR_FEICOES=$(psql -h $SERVIDOR -p $PORTA -d $BANCO_DADOS -U $USUARIO -t -c "SELECT count(*) FROM $NOME_VIEW;") | |
if [ ! $CONTADOR_FEICOES -eq 0 ]; then | |
echo "existem $CONTADOR_FEICOES feicoes na view $NOME_TABELA. exportando..." | |
if [ "$FORMATO" = "fgdb" ]; then | |
sh ex_fgdb.sh $SERVIDOR $PORTA $BANCO_DADOS $USUARIO $SENHA $CAMINHO_SAIDA $NOME_TABELA $NOME_VIEW $LAYER_TYPE | |
else | |
sh ex_shp.sh $SERVIDOR $PORTA $BANCO_DADOS $USUARIO $SENHA $CAMINHO_SAIDA $NOME_TABELA $NOME_VIEW | |
fi | |
else | |
echo "nao existem feicoes para $NOME_VIEW" | |
fi | |
echo $SEPARADOR | |
done | |
echo "exportacao concluida. limpando arquivos temporarios" | |
rm -rf exportar.temp | |
unset IFS | |
unset PGPASSWORD | |
echo "exportacao finalizada" | |
echo $SEPARADOR | |
echo $SEPARADOR | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Infraestrutura geral. | |
*/ | |
CREATE SCHEMA temporario; | |
CREATE TABLE camada ( | |
id SERIAL PRIMARY KEY, | |
esquema varchar(256) NOT NULL DEFAULT 'public', | |
nome_tabela varchar(256) NOT NULL, | |
nome varchar(256) NOT NULL, | |
descricao varchar(512), | |
exportar BOOLEAN DEFAULT TRUE, | |
nome_view varchar(512) NULL | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment