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

Code:

for(int row=0;row<99;row++){
int xoff,yoff;
        yoff=row*metadata.tilesizeY ;
        for(int col=0;col<99;col++){
              xoff=col*metadata.tilesizeX;
              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);
              if(res!=PGRES_TUPLES_OK){
                    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);
              PQclear(retval);
              query.clear();
              query.str("");

        }
}
GDALClose(dstDS);
share|improve this question

3 Answers 3

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 http://www.postgresql.org/docs/9.1/static/datatype-binary.html for more information.

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

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

share|improve this answer

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.