[gdal-dev] The problem when using ReadRaster(C#) method

Tamas Szekeres szekerest at gmail.com
Wed Aug 31 06:15:55 EDT 2011

You should make sure about the actual representation of the raster image,
whether it represents the pixel as floats as you have used float arrays in
the code. The last 2 parameters are used to define the byte offset of the
pixels and lines in the image ( for more info see the

Further C# related samples can be found here:

Best regards,


2011/8/31 hitweiran <hitweiran at sina.com>

> I want to read a multiband image(in format of .img) by using method
> ReadRaster, however, I encount some problems. I just can't understand why
> the data loaded to memory is wrong?
> the code is like this
> OSGeo.GDAL.Dataset dataSet =
> OSGeo.GDAL.Gdal.Open(@"G:\building.img",OSGeo.GDAL.Access.GA_ReadOnly);
> int width = dataSet.RasterXSize;
> int height = dataSet.RasterYSize;
> int Band_Numbers = dataSet.RasterCount;
> float [] buffer_first = new float [width * height];
> OSGeo.GDAL.Band One_Band = dataSet.GetRasterBand(1);
> One_Band.ReadRaster(0, 0, width, height,buffer_first, width, height, 0,0);
> However, the output is wrong!
> I watch the variable "buffer_first" in watch window, and discoverse that
> the
> data is quite terrible-some data is such as 2.818478E+21,5.065476E+32, or
> -6.131138E-11 and so on;
> So I suspect my datatype is mismatch to data in img file, or the last two
> arguments in ReadRaster is mistake, because I don't know the meaning of
> last
> two parameters.
> Thanks a lot for your answer!
> --
> View this message in context:
> http://osgeo-org.1803224.n2.nabble.com/The-problem-when-using-ReadRaster-C-method-tp6745826p6745826.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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20110831/266b56dc/attachment.html

More information about the gdal-dev mailing list