如何一次性从 PostGIS 导出栅格?
How to export raster from PostGIS in one go?
在光栅导出脚本的简化规范示例(我经常在论坛和书籍中看到)中,OID(由 lo_create(0) 返回, 这里是 9585208) 必须在倒数第二个脚本行之前知道 (lo_export 9585208 'C:/temp/raster.png'):
SELECT oid, lowrite(lo_open(oid, 131072), img) As num_bytes
FROM (
VALUES (
lo_create(0),
(SELECT ST_AsPNG(rast)
FROM bag_o_rasters
LIMIT 1)
)
) As v(oid, img);
lo_export 9585208 'C:/temp/raster.png'
SELECT lo_unlink(9585208);
我很难弄清楚如何一次性将 PSQL cli 实用程序用于 运行 这个脚本,即如何传达 lo_create( 0)到lo_export命令。似乎 lo_export 是客户端命令,它无法消化任何查询结果...请帮忙...
最后,有一个 PSQL 命令 \gset 将值存储到脚本变量中,文档说:
\gset sends the current query buffer to the server and stores the query's
output into psql variables. The query to be executed must return
exactly one row. Each column of the row is stored into a separate
variable, named the same as the column.
这里是相应修改的脚本:
SELECT lo_create(0) as blob_oid
\gset
SELECT oid, lowrite(lo_open(oid, 131072), img) As num_bytes
FROM (
VALUES (
:blob_oid,
(SELECT ST_AsPNG(rast)
FROM bag_o_rasters
LIMIT 1)
)
) As v(oid,img);
\lo_export :blob_oid 'C:/temp/raster.png'
SELECT lo_unlink(:blob_oid);
在光栅导出脚本的简化规范示例(我经常在论坛和书籍中看到)中,OID(由 lo_create(0) 返回, 这里是 9585208) 必须在倒数第二个脚本行之前知道 (lo_export 9585208 'C:/temp/raster.png'):
SELECT oid, lowrite(lo_open(oid, 131072), img) As num_bytes
FROM (
VALUES (
lo_create(0),
(SELECT ST_AsPNG(rast)
FROM bag_o_rasters
LIMIT 1)
)
) As v(oid, img);
lo_export 9585208 'C:/temp/raster.png'
SELECT lo_unlink(9585208);
我很难弄清楚如何一次性将 PSQL cli 实用程序用于 运行 这个脚本,即如何传达 lo_create( 0)到lo_export命令。似乎 lo_export 是客户端命令,它无法消化任何查询结果...请帮忙...
最后,有一个 PSQL 命令 \gset 将值存储到脚本变量中,文档说:
\gset sends the current query buffer to the server and stores the query's output into psql variables. The query to be executed must return exactly one row. Each column of the row is stored into a separate variable, named the same as the column.
这里是相应修改的脚本:
SELECT lo_create(0) as blob_oid
\gset
SELECT oid, lowrite(lo_open(oid, 131072), img) As num_bytes
FROM (
VALUES (
:blob_oid,
(SELECT ST_AsPNG(rast)
FROM bag_o_rasters
LIMIT 1)
)
) As v(oid,img);
\lo_export :blob_oid 'C:/temp/raster.png'
SELECT lo_unlink(:blob_oid);