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 raster data in a postgis server (I am able to see it in qgis). When I retrieve it and form gtiff image out of it using gdal, the generated image is not correct (there is a coloring problem). I am able to retrieve the metadata correctly.

For raster I am doing st_AsBinary(rast). And then passing it to gdal raster io buffer parameter

Metadata is read first successfully. Image was stored as tiles


for(int row=0;row<99;row++){
int xoff,yoff;
        yoff=row*metadata.tilesizeY ;
        for(int col=0;col<99;col++){
              query<<"select st_asbinary(rast) from public.tkptest where rid ="<<(row*99)+col+1;
              retval = PQexec(options.connection,query.str().c_str());
              res= PQresultStatus(retval);
                    std::cout<<"We did not get any data\n";
                    return res;
              dstDS->RasterIO(GF_Write,xoff,yoff,metadata.tilesizeX ,metadata.tilesizeY ,PQgetvalue(retval,0,0),metadata.tilesizeX *metadata.datasize,metadata.tilesizeY *metadata.datasize  ,metadata.dtype,metadata.numBands,panBandMap,0,0,0);

share|improve this question

ST_AsBinary return raster info in wkb format to store one need to convert it to char array.

share|improve this answer

Apart from ST_AsBinary, the other option is to use GDAL, as you said. The problem with that is the GDAL PostGIS Raster driver. I'm actually working on it (I'm the driver's developer). Results expected before September.

share|improve this answer

My guess would be that you need to extract the data from WKB into something GDAL knows. Furthermore you should be aware what the output of your database looks like, see for more information.

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.