Ferramentas do usuário

Ferramentas do site


postgis

POSTGIS

Pré-requisitos:

  • Instale Postgres
  • Instale plugin Postgis
  • Coloque os binários nas variáveis de ambiente do windows

ADD SHP

shp2pgsql -I -s 31982 -W "LATIN1" PR_rodovias.shp PR_rodovias | psql -h <ip> -U postgres -d <nome_banco>

ADD Raster

raster2pgsql -s 4326 -I -C imagem.tif public.nome_da_tabela > raster.sql
psql -h <ip_do_servidor> -p <porta> -U <usuario> -d <nome_do_banco> -f raster.sql

MULTIPLOS UPLOADS

import os
import subprocess

PASTA = r'C:\\Users\\xxx\\xxx\\xxx'  
USUARIO = ''
SENHA = ''
BANCO = ''
HOST = ''
SRID = '31982'

for arquivo in os.listdir(PASTA):
    if arquivo.lower().endswith('.shp'):
        caminho_shp = os.path.join(PASTA, arquivo)
        nome_tabela = os.path.splitext(arquivo)[0]
        nome_tabela = nome_tabela.replace("ç", "c").replace("Ç", "C").replace("ã","a").replace("Ã","A")

        comando = f'shp2pgsql -I -s {SRID} "{caminho_shp}" "{nome_tabela}" | psql -h {HOST} -U {USUARIO} -d {BANCO}'

        print(f'Importando {arquivo} para a tabela {nome_tabela}...')
        resultado = subprocess.run(comando, shell=True, env={**os.environ, 'PGPASSWORD': SENHA})
        if resultado.returncode == 0:
            print(f'✔ {arquivo} importado com sucesso!\n')
        else:
            print(f'✖ Erro ao importar {arquivo}!\n')
postgis.txt · Última modificação: por jdos

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki