创建数据库
create database alldata;
\c alldata
create extension postgis;
create schema shpdb;
create schema tiffdb;
\q
也可以使用python自带的数据库 ,使用gdal命令
使用python批量处理
# -*- coding: utf-8 -*-
import os
import subprocess
import time
t1=time.time()
s=0
t=0
for wroot, wdirs, wfiles in os.walk(os.getcwd()):
for file in wfiles :
if file.endswith('.tif') or file.endswith('.shp'):
fname,lname= file.split('.')
if lname =='tif' :
s += 1
postgresql='raster2pgsql -s 4326 -C {} tiffdb.{} | psql -h localhost -p' \
' 5432 -U postgres -d alldata -W '.format(os.path.join(wroot, file), fname)
subprocess.run(postgresql, shell=True)
if lname == 'shp':
t += 1