[postgis-users] raster retrieval

Yogesh Dahiya yogesh at vizexperts.com
Thu Jun 21 08:06:11 PDT 2012


I have  raster data into postgis server(I am able to see it in qgis).

When I retrieve it and form gtiff image out of it using gdal  , Image
generated is not proper (coloring problem).

I am able to retrieve metadata correctly

For raster I am doing  st_AsBinary(rast)

And then passing it to gdal rasterio buffer parameter

Attach file contain original and Downloaded image

43J is original

download_temp.tif is downloaded one.

 

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

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20120621/0069d68f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 43J.tif
Type: image/tiff
Size: 6278338 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20120621/0069d68f/attachment.tif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: download_temp.tif
Type: image/tiff
Size: 8 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20120621/0069d68f/attachment-0001.tif>


More information about the postgis-users mailing list