mentby.com
Blog | Jobs | Help | Signup | Login

Hi guys,

Is it possible to create an actual jpeg image using ST_AsJPEG? For example

select ST_AsJPEG(rast) from area_dem \g image.jpg

Joan


Joan Tue, 14 Feb 2012 03:26:39 -0800

You can also use gdal_translate...

Pierre


Pierre Racine Tue, 14 Feb 2012 06:22:28 -0800

I ended up binary-editing the result afterwards.

Anyway, first step is declaring a binary cursor,
redirecting output to a file and calling the function.

For the binary editing, I looked at another file with
my expected format to tell where it started (human eye
pattern matching).

Much better, when it works (it wasn't working for me).

--strk;

  ,------o-.
  |   __/  |    Delivering high quality PostGIS 2.0 !
  |  / 2.0 |     http://strk.keybit.net
  `-o------'


Sandro Santilli Tue, 14 Feb 2012 06:27:42 -0800

Thanks,

Do you see any way to make the file directly readable (without having to edit it)?

Pierre

postgis-users mailing list
postgis-users*******/mailman/listinfo/postgis-users


Pierre Racine Tue, 14 Feb 2012 06:39:54 -0800

Yes, I want to create a jpeg/tiff file. I am new to cursors, how would that
work in a query.


Joan Tue, 14 Feb 2012 07:10:35 -0800

I could find no way with current psql. Something to improve there.
You can of course do it with scripts.

--strk;

  ,------o-.
  |   __/  |    Delivering high quality PostGIS 2.0 !
  |  / 2.0 |     http://strk.keybit.net
  `-o------'


Sandro Santilli Tue, 14 Feb 2012 07:26:24 -0800

So you might have to write a script connecting to PostgreSQL and writing the file for you. See an example in:

http://www.bostongis.com/blog/index.php?/archives/175-Minima[..]

Pierre


Pierre Racine Tue, 14 Feb 2012 08:05:22 -0800

We have this documented in the docs.

http://www.postgis.org/documentation/manual-svn/using_raster[..]
ter_Applications

There is an example for doing it with PHP, .NET, Java, and PLPython

Sorry don't have one for psql only.  Haven't tried using psql for outputting
files.

Regina http://www.postgis.us


Paragon Corporation Tue, 14 Feb 2012 12:28:05 -0800

The last two solutions result in a black square, which I think is the tile.
But it's a good start. I will have to look more into that.
Regina, I have tried using \g to out put to a file but the file is
corrupted.

I appreciate the help.

Joan


Joan Tue, 14 Feb 2012 13:23:00 -0800

Yah psql doesn't make it easy.  I've put in an example of doing it in docs.
Which takes tips from this article: http://people.planetpostgresql.org/andrew/index.php?/archive[..]
ck-challenge.html

There are other examples in that article but this is the only one that
doesn't require Perl or Unix so is more cross platform.

I think strk has one too though his probably requires perl or some unixy
thing.


Docs I don't think have rebuilt yet, but basic script is this:

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);

Thanks,
Regina
h < http://www.postgis.us> > ttp://www.postgis.us



  _____


Paragon Corporation Tue, 14 Feb 2012 14:32:21 -0800

Here it is in the docs now:
http://postgis.refractions.net/documentation/manual-svn/usin[..]
l#RasterOutput_PSQL

  _____


Paragon Corporation Tue, 14 Feb 2012 14:43:27 -0800

Curious that the question was never raised for ST_AsKML(geometry)...


Pierre Racine Tue, 14 Feb 2012 14:54:09 -0800

ST_AsKML(geometry) would be returning XML so suffers no binary issues.

-bborie

--
Bborie Park
Programmer
Center for Vectorborne Diseases
UC Davis
530-752-8380
bkpark*******


Bborie Park Tue, 14 Feb 2012 15:03:20 -0800

Hi Regina

Citation from there: "Sadly PSQL doesn't have easy to use built-in
functionality for outputting binaries..."

Did anyone show and discuss this issue with postgres specialists?

--Stefan


Stefan Keller Wed, 15 Feb 2012 13:37:21 -0800

I don't think there's much to discuss.
I'm sure a patch to psql would be welcome.

--strk;

  ,------o-.
  |   __/  |    Delivering high quality PostGIS 2.0 !
  |  / 2.0 |     http://strk.keybit.net
  `-o------'


Sandro Santilli Wed, 15 Feb 2012 23:35:28 -0800

Sorry, I did not realize that the solution is straight forward :->

--Stefan


Stefan Keller Thu, 16 Feb 2012 06:17:33 -0800



Related Topics

Post a Comment