Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a raster which is split into 30 tiles and I want to dump them all into PNGs.

I've read the documentation but still don't know how to dump it well.

If i use ST_Histogram, i get numbers, think the raster is well inserted,

SELECT band, (stats).*
FROM (SELECT rid, band, ST_Histogram(rast, band) As stats
      FROM "corine-g100_06-v15" CROSS JOIN generate_series(1,3) As band
      WHERE rid=2) As foo;
share|improve this question


The output of ST_AsPNG is the binary blob of a PNG file, so you output it to a file as you would any other binary document saved in PostgreSQL . It really depends what you are using as your tool.

For example we have examples of this that output to browser in thsese quick examples we put together to demonstrate how it is done. Download the examples to see.

Only difference in your case is you would output to a file instead ofr browser stream.

You can also do it with plpython, plperl, or any other postgresql pl language that can write to a file if you just want to output to the database server. We'l try to put together examples of that in the next month or so.

share|improve this answer

There are a couple of ways to do this, noted here: and here: I've used both methods successfully with PostGIS 2.1.1, but found the first method a bit more concise on a Linux server. For example:

COPY (SELECT encode(ST_AsTiff(ST_ColorMap((SELECT rast FROM worldclim.bio12_2_5m), 1, 
'100% 1,70,54
90% 1,70,54
80% 1,108,89
70% 2,129,138
60% 54,144,192
50% 103,169,207
40% 166,189,219
30% 208,209,230
20% 236,226,240
10% 255,247,251
0% 255,247,251
nodata 0,0,0')), 'hex')) 
TO '/var/www/https/maps/tmp/bio12_2_5m.hex';

Then drop back to the OS and do:

xxd -p -r bio12_2_5m.hex > bio12_2_5m.tiff

Depending on your rasters this should work for a PNG dump too, but mine only worked to a TIFF.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.