Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

I've read the documentation http://postgis.net/docs/RT_ST_AsPNG.html 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
add comment

2 Answers

Avances,

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.

http://www.bostongis.com/blog/index.php?/archives/175-Minimalist-Web-based-PHP-PostGIS-2.0-Spatial-GeometryRaster-Viewer.html 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
add comment

There are a couple of ways to do this, noted here: http://petewarden.com/2013/08/31/how-to-save-an-image-to-disk-from-postgis/ and here: http://www.postgis.org/documentation/manual-svn/using_raster.xml.html#RasterOutput_PSQL. 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
add comment

Your Answer

 
discard

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.