raster导入postgres Windows命令
cmd命令行
raster2pgsql -s 4326 -I -C -M C:\Users\tt\Downloads\tmean_19_tif\*.tif -F -t 256x256 tmean_19 | psql -h localhost -p 5432 -U postgres -d raster -W
- 1
之后输入数据库密码
导入后数据表中的raster字段不显示数据,通过读取方式可测试
# -*- coding: utf-8 -*-
import psycopg2
# Connect to an existing database
conn = psycopg2.connect('host=localhost port=5432 user=postgres password=123 dbname=raster')
# Open a cursor to perform database operations
cur = conn.cursor()
# Execute SQL query
# cur.execute("SELECT ST_AsTIFF(rast, 'LZW') AS rasttiff FROM staging.wsiearth WHERE rid=1;")
cur.execute("SELECT ST_AsTIFF(ST_Union(rast), 'LZW') AS rasttiff FROM public.tmean_19 WHERE filename='tmean10_19.tif';")
# Fetch data as Python objects
rasttiff = cur.fetchone()
# Write data to file
if rasttiff is not None:
open('D:/mapnik/mapnik-v2.2.0/shp/mapnik/tmean1.tif', 'wb').write(str(rasttiff[0]))
# Close communication with the database
cur.close()
conn.close()
用python的pip工具下载安装包
C:\Python27\Scripts\pip.exe
- 1
http://blog.csdn.net/theonegis/article/details/55100365
http://blog.csdn.net/theonegis/article/details/55050943