[gdal-dev] Transposing image data using RasterIO

Frank Warmerdam warmerdam at pobox.com
Fri Jun 17 17:41:39 EDT 2011


On 11-06-17 03:23 PM, Paul Mallas wrote:
> Hello,
>
> I am trying to transpose image data (i.e., swap lines and columns) and am
> struggling to make it work properly. I think this should be possible through
> RasterIO, but so far no luck. Any suggestions?
>
> My approach so far has been like this, with image nXsize by nYsize:
>
> void *pData = VSIMalloc2(nXSize, (GDALGetDataTypeSize(eType) / 8));
>
> for (int iLine = 0; iLine < nYSize; iLine++) {
>
> // Read in row (line)
> eErr = poSrcBand->RasterIO(GF_Read, 0, iLine, nXSize, 1, pData,
> nXSize, 1, eType, 0,0);
>
> // Now I want to write a column, nothing I tried here has worked
> eErr = poDstBand->RasterIO(GF_Write, .......

Paul,

You should be able to write this column wise like:

   poDstBand->RasterIO( GF_Write, iLine, 0, 1, nXSize,
                        pData, 1, nXSize, eType, 0, 0 );

Note that this can be pretty inefficient depending on the format and
how it is blocked.

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent



More information about the gdal-dev mailing list