Gdal short raster readblock

Dec 11, 2010 at 6:22 PM

I am posting to confirm that there is no error in the GdalShortRaster.cs file.

Line 149 of GdalShortRaster.cs

  result[row] = new short[base.NumColumns];

shouldn't it be NumRows instead of NumColumns because we are reffering to rows not columns ?

i am just trying to read partially a  large raster file using the ReadBlock Function like that


Dim Xoffset As Integer = 21600

Dim Yoffset As Integer = 3600

'Request size 3600x3600 from (3600,21600) on raster of 43200x18000.        

Dim sizeX As Integer = newNumOfRows        

Dim sizeY As Integer = newNumOfCols        

Dim Ir As IRaster = oldR.ReadBlock(Xoffset, Yoffset, sizeX, sizeY)        

Dim dataExtracted As Raster(Of Short) = CType(Ir, Global.DotSpatial.Data.Raster(Of Short))

        For row As Integer = 0 To newNumOfRows - 1

            For col As Integer = 0 To newNumOfCols - 1

                Dim value As Double

                value = dataExtracted.Value(row, col)

                newR.Value(row, col) = value            




is there an  irc chat room where i can contact you?

Thanks in advance,


Dec 11, 2010 at 6:51 PM

In a jagged array, a "Row" is defined as an array that has one entry for each column, so int would read like Data[row] = new double[numColumns];

You want the number of rows when dimensioning the entire jagged array:

Block = new double[numRows][];

Block[0] = new double[numColumns];


Hope this isn't too confusing.  I'd also strongly recommend that if you have a Raster(Of Short) that you access the values using the "Data[row][column]" format rather than the "Value(row, col)" format.  It will run about five times faster that way.





Dec 11, 2010 at 7:10 PM
Edited Dec 11, 2010 at 7:30 PM

Thank you very much  Ted. I got it.

Anyway ,

I always get an "index out of range" exception.(in the line noted below)

I Request a size of  3600x3600 from (21600,3600) on a raster of 43200rows x18000 columns.

I am using the generic grid format files from (future datasets ) which are about 1.5 gb for each month.

I want the 16th tile of the ethire earth so i am trying to create a new smaller raster from the big one.

As you requested the new code i am using is :

 Dim Xoffset As Integer = 21600

        Dim Yoffset As Integer = 3600        

 Dim aShortRaster As Raster(Of Short) = oldR.ToShortRaster()        

 Dim data As Short()() = aShortRaster.ReadRaster(Xoffset, Yoffset, 3600, 3600)  '<---  INDEX OUT OF RANGE OCCURES HERE!

        For row As Integer = 0 To newNumOfRows - 1

            For col As Integer = 0 To newNumOfCols - 1

                newR.Value(row, col) = data(row)(col)





Thanks again,




Dec 11, 2010 at 8:19 PM

I think that the line 

for (int row = 0; row < base.NumRows; row++)

should be 

for (int row = 0; row < sizeY; row++)

in the GdalShortRaster.cs file.

since variable result  is declared as folows

short[][] result = new short[sizeY][];

Dec 12, 2010 at 3:04 PM

Now your cooking =).  I will post the fix if it hasn't been fixed yet.