Re: [gdal-dev] How to read first line pixel values of an image into buffer

Ivan Lucena ivan.lucena at pmldnet.com
Thu May 20 08:17:29 EDT 2010


Hi there,

>  -------Original Message-------
>  From: mail2vajram <mail2vajram at gmail.com>
>  To: gdal-dev at lists.osgeo.org
>  Subject: [gdal-dev] How to read first line pixel values of an image into buffer
>  Sent: May 20 '10 02:30
>  
>  
>  I am using the following code to read pixel values. It read only one pixel
>  value..how to read entire row..
>  
>  generally this code is used to read 0th column 1st row and return pixel
>  value into buffer.  
>  code:    
>  Band band = ds.GetRasterBand(1);
>  double[] buffer = new double[ds.RasterXSize];
>  band.ReadRaster(0, 1,1,1, buffer, 1,1, 1, 1);
>  
>  
>  but when i am using the following code i am not able to getting entire first
>  row values values.
>  
>  Band band = ds.GetRasterBand(1);
>  double[] buffer = new double[ds.RasterXSize];
>  band.ReadRaster(0, 1,ds.RasterXSize,1, buffer, 1, 1, 1, 1);

I believe that the ReadRaster() for C# documentation is missing but it should be based on GDALRasterIO:

http://gdal.org/gdal_8h.html#f26fead53c02f8035150cc710c156752

So you are reading from the second row, all the row, but storing in just one pixel. That is because you have 1's on  nBufXSize and nBugYSize arguments.

I think you should change your call to something like:

band.ReadRaster(0, I, ds.RasterXSize,1, buffer, ds.RasterXSize,1);

Where I is a index from 0 to ds.RasterYSize.

The C# out-complete probably will show the order of arguments and what are the options to suppress optional arguments. I believe you don't need to specify nPixelSpace and nLineSpace, if you don't want to.

Regards.

>  
>  Can any body suggest me which parameter i need to change. Iam using C# code
>  --
>  View this message in context: http://osgeo-org.1803224.n2.nabble.com/How-to-read-first-line-pixel-values-of-an-image-into-buffer-tp5078547p5078547.html
>  Sent from the GDAL - Dev mailing list archive at Nabble.com.
>  _______________________________________________
>  gdal-dev mailing list
>  gdal-dev at lists.osgeo.org
>  http://lists.osgeo.org/mailman/listinfo/gdal-dev
>  


More information about the gdal-dev mailing list