0

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);
1

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

|improve this answer|||||
0

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.

|improve this answer|||||
0

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.

|improve this answer|||||

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.