[Gdal-dev] GDAL in delphi .. reading pixel values (Esri grids)
Andrew Finley
afinley at gis.umn.edu
Mon Apr 26 09:42:50 EDT 2004
Hi JK,
I think there is a similar chunk of code in the list archives, but here
it is again. Attached are two files, getPixelValueGdal.cpp and
parameterfile. The parameterfile describes the image location and the
coordinate file (i.e., point xy locations). This is set up for ERDAS
images, I think you will only have to change the driver for it to read
grids. Hope this helps. Let me know if you have any questions.
-Andy
On Mon, 2004-04-26 at 00:48, jk nz wrote:
> 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
>
> _______________________________________________
> Gdal-dev mailing list
> Gdal-dev at remotesensing.org
> http://remotesensing.org/mailman/listinfo/gdal-dev
--
Andrew Finley, Research Fellow
Department of Forest Resources
College of Natural Resources
University of Minnesota
305 Green Hall
1530 Cleveland Avenue N.
St. Paul, MN 55108
Ph 612-624-1714 office
www.cnr.umn.edu/FR/people/facstaff/finley/index.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: getPixelValueGdal.cpp
Type: text/x-c++
Size: 4654 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/gdal-dev/attachments/20040426/610735b5/getPixelValueGdal.bin
-------------- next part --------------
COORD_FILE st_louis_cloudfree_pts.csv
OUT_FILE /st_louis_cloudfree_pts_bands.csv
COORD_FILE_ROWS 3674
COORD_FILE_COLS 16
XCOORD_COLUMN 6
YCOORD_COLUMN 7
IMAGE_FILE ssf_raw_8bit_stlouis.img
More information about the Gdal-dev
mailing list