创建pgraster的overview表以及overviewconstrants表约束

创建pgraster的overview表以及overviewconstrants表约束

练习postgis官方文档中有关pgraster部分的内容。记录下笔记。

在pgraster导入的时候raster2pgsql这个插件使用的时候,忘记使用-l这个参数来建立overview

这个时候需要手动在写sql添加

1.创建一个overview表

 

CREATE TABLE temp_overviewtable AS SELECT
ST_AddBand(
  ST_MakeEmptyRaster(1024, 1024, 0, 0, 4),
  1, '8BSI'::text, -129, NULL
) r2;

 

2.创建与raster表字段对应关系,使用函数AddOverviewConstraints来实现

 

select addoverviewconstraints('temprature','rast','temp_overviewtable','r2','6')

 

3.创建完成,查询语句查看:

select * from raster_columns
select * from raster_overviews

select st_astiff(st_union(rast)) as rasttiff from public.temprature where filename='wc2.0_2.5m_tmax_01.tif' limit 10

4.关于导出pgraster查看效果:有输入了,当然想看一下输出是很什么样的,而postgis恰恰是去图形化的,压根没有图形可视化的窗口,所以想看效果只能通过写代码看。

怎么写代码,些什么代码?从官网上看有php,aps.net,java的,还有各plpython的方式的这个要求的安装plpython关于这种方式自己去官网试试吧。

5.我选了csdn上的一篇博文:https://blog.csdn.net/theonegis/article/details/55100365

来试,总是报错TypeError: a bytes-like object is required, not 'str'。修改了其中的输出的代码。见下面代码的粉色部分


import psycopg2
conn=psycopg2.connect('host=localhost port=5432 user=postgres password=12345 dbname=name')

cur=conn.cursor()

#这里可以把sql拿出来去pg里面试一下看看是不是可用,是不是需要很久的时间,为了效率我这里限制只导出第一幅

cur.execute("select st_astiff(st_union(rast)) as rasttiff from public.temprature where filename='wc2.0_2.5m_tmax_01.tif' limit 1")

rasttiff=cur.fetchone()

#http://initd.org/psycopg/docs/cursor.html可以来psycopg官网看看相关的参数
if rasttiff is  not None:

#输出位置的选择,output是我的输出文件名
    open(r'E:\data\temprature\output.tif','wb').write(rasttiff[0])

cur.close()
conn.close()

6.找到我的e盘的对应位置,看我的图出来了哈哈。

 

具体参考原文如下:

http://postgis.net/docs/RT_AddOverviewConstraints.html

Synopsis

boolean AddOverviewConstraints(name ovschema, name ovtable, name ovcolumn, name refschema, name reftable, name refcolumn, int ovfactor);

boolean AddOverviewConstraints(name ovtable, name ovcolumn, name reftable, name refcolumn, int ovfactor);

Description

Adds constraints on a raster column that are used to display information in the raster_overviews raster catalog.

The ovfactor parameter represents the scale multiplier in the overview column: higher overview factors have lower resolution.

When the ovschema and refschema parameters are omitted, the first table found scanning the search_path will be used.

Availability: 2.0.0

Examples

CREATE TABLE res1 AS SELECT
ST_AddBand(
  ST_MakeEmptyRaster(1000, 1000, 0, 0, 2),
  1, '8BSI'::text, -129, NULL
) r1;

CREATE TABLE res2 AS SELECT
ST_AddBand(
  ST_MakeEmptyRaster(500, 500, 0, 0, 4),
  1, '8BSI'::text, -129, NULL
) r2;

SELECT AddOverviewConstraints('res2', 'r2', 'res1', 'r1', 2);

-- verify if registered correctly in the raster_overviews view --
SELECT o_table_name ot, o_raster_column oc,
       r_table_name rt, r_raster_column rc,
       overview_factor f
FROM raster_overviews WHERE o_table_name = 'res2';
  ot  | oc |  rt  | rc | f
------+----+------+----+---
 res2 | r2 | res1 | r1 | 2
(1 row)
		

See Also

Section 5.2.2, “Raster Overviews”DropOverviewConstraintsST_CreateOverviewAddRasterConstraints

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值