From 148bed9a943dd7fed30e2145c0f3ccabe4778cef Mon Sep 17 00:00:00 2001 From: Regina Obe Date: Tue, 14 Feb 2012 22:21:48 +0000 Subject: [PATCH] Example of how to use only psql to output a raster image. git-svn-id: http://svn.osgeo.org/postgis/trunk@9192 b70326c6-7e19-0410-871a-916f4a2858ee --- doc/using_raster_dataman.xml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/doc/using_raster_dataman.xml b/doc/using_raster_dataman.xml index 9b946020c..c6e6db5f9 100644 --- a/doc/using_raster_dataman.xml +++ b/doc/using_raster_dataman.xml @@ -718,5 +718,29 @@ $$ LANGUAGE plpythonu;]]> C:/temp/slices5.png + + Outputting Rasters with PSQL + Sadly PSQL doesn't have easy to use built-in functionality for outputting binaries. This is a bit of a hack and based on one of the suggestions outlined in + Clever Trick Challenge -- Outputting bytea with psql that piggy backs on PostgreSQL somewhat legacy large object support. To use first launch your psql commandline connected to your database. + + Unlike the python approach, this approach creates the file on your local computer. + SELECT oid, lowrite(lo_open(oid, 131072), png) As num_bytes + FROM + ( VALUES (lo_create(0), + ST_AsPNG( (SELECT rast FROM aerials.boston WHERE rid=1) ) + ) ) As v(oid,png); +-- you'll get an output something like -- + oid | num_bytes +---------+----------- + 2630819 | 74860 + +-- next note the oid and do this replacing the c:/test.png to file path location +-- on your local computer + \lo_export 2630819 'C:/temp/aerial_samp.png' + +-- this deletes the file from large object storage on db +SELECT lo_unlink(2630819); + + -- 2.40.0