I imported my image with three bands (RGB) with 100*100 tiles using raster2pgsql into the DB. Now, I need to export those tiles separately. I used the following code but it produces a table

 select st_aspng(st_reclass(rast,1,'0-100:0-100','8BUI',0)) from myraster.test where rid=1;

So I need some help to improve this code or even revise it to a suitable form.


I found the solution to this question:

Using gdalwarp and PG was worked:

gdalwarp -t_srs EPSG:4326 -tr 100 100 -of PNG -r bilinear PG:"host=localhost port=5432 dbname='postgis' user='***' password='***' schema='chp01' table='raster_table' mode='1'" rast_name.png

mode - option is used to know the expected arrangement of the raster table. There are 2 possible values

mode=1 - ONE_RASTER_PER_ROW mode. In this case, a raster table is considered as a bunch of different raster files. This mode is intended for raster tables storing different raster files. It’s the default mode if you don’t provide this field in connection string.

mode=2 - ONE_RASTER_PER_TABLE mode. In this case, a raster table is considered as a unique raster file, even if the table has more than one row. This mode is intended for reading tiled rasters from database.

In my case since I imported the image in different tiles, number 1 can provide suitable result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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