在PostGIS中剪切光栅对象

问题描述:

我正在尝试使用带有参考的shapefile剪切光栅对象(来自PostGIS表格),从多边形区域提取光栅数据。我的目标与限幅光栅工作纳入R.在PostGIS中剪切光栅对象

我以这种方式切割:

CREATE TABLE clippingtable as (SELECT (ST_Union(ST_Clip(raster.rast, ST_Transform(polygon.geom, ST_SRID(raster.rast))))) 
    FROM originalraster as raster, originalshape as polygon 
    WHERE ST_Intersects(raster.rast, polygon.geom)) 

的gdalinfo输出是:

$gdalinfo "PG:host=localhost port=5432 dbname='testdb' schema='public' table=clippingtable" 
ERROR 1: Error retrieving raster metadata 
gdalinfo failed - unable to open 'PG:host=localhost port=5432 dbname='testdb' schema='public' table=clippingtable'. 

在R I正在使用这些功能:

dsn="PG:dbname=testdb host=localhost port=5432 table=clippingtable" 
rgdal::GDALinfo(dsn) 
readGDAL(dsn) 

输出是: “错误。本地(.Object,...):错误检索光栅满足adata“

原始表格(切割前)我可以正常使用我的栅格。

任何想法我做错了什么?

谢谢。

+0

您可以用'crop'从光栅包?你可以简单地用'readOGR'读入shape文件,然后'裁剪'它。 – Badger

完成。我需要创建约束来加载表列中的空间信息。

我使用了PostGIS的功能 “AddRasterConstraints” 来解决问题

功能文档: http://postgis.net/docs/manual-2.2/RT_AddRasterConstraints.html