[Gdal-dev] GDAL in delphi .. reading pixel values (Esri grids)

jk nz jk_nzd at hotmail.com
Mon Apr 26 01:48:01 EDT 2004


Has anyone tried using GDAL from the Borland Delphi language?

I have been mostly sucessful in doing so, but having problems reading pixel 
values from an esri grid..

Does anyone have sample code of reading pixels? C is ok .. I have seen 
sample of reading blocks but that wasnt quite what I wanted ...

I do not know how to extract the pixel values as I dont know how they are 
laid out in memory .. is it a 2d grid, or a 1d grid?

eg is it laid out in memory as

row1 [px1][px2][px3][...]
row2 (possible some memory gap in between rows) [px10][px11][...]

or as row1 [px1][px2][...] (row2, no gap in memory, next pixel is at address 
pxN+ sizeof(px)) [px10][...]

It appears I have to use pointer arithmetic to index the block, ie pixelN := 
block[index] works fine if it is a 1d grid in memory, but its not so easy if 
its a 2d grid, as the operator block[x,y] is not valid in delphi

So I'm trying to figure out what happens at the end of a row? is the first 
element of the next row located in the next memory address or ...?

Any help appreciated

Regards

JK.


Here is my code: - everything appears to work, apart from reading individual 
pixel values.

            for i := 0 to nYBlocks - 1 do // i = Y block index
              for j := 0 to nYBlocks - 1 do // j = X block index
              begin
                GDALReadBlock(RasterBand, j, i, pafScanline);

                // compute which part of the block is valid for partial 
blocks
                if(i * nBlockYSize > nY) then
                  nYValid := nY - i * nBlockYSize
                else
                  nYValid := nBlockYSize;

                if(j * nBlockXSize > nX) then
                  nXValid := nX - j * nBlockXSize
                else
                  nXValid := nBlockXSize;

                doubleptr := @pafScanline;

                for k := 0 to nYValid - 1 do // k = Y cell index
                  for l := 0 to nXValid - 1 do // l = X cell index
                  begin
                    inc(doubleptr);
                    cell := doubleptr^;
                    // debugging stuff, did we get an ok value or not?
                    if cell > 0 then
                      ShowMessage(FloatToStr(cell));
                  end; // for l, for k
              end; // for j, for i

_________________________________________________________________
Need more speed? Get Xtra JetStream  @ http://xtra.co.nz/jetstream




More information about the Gdal-dev mailing list