If you are creating a new project- set up GDAL & C# environment as described here
private static void ReadRasterBlocks(ref Dataset valueRaster)
{
Band bandValueRaster = valueRaster.GetRasterBand(1);
int rasterRows = valueRaster.RasterYSize;
int rasterCols = valueRaster.RasterXSize;
const int blockSize = 1024;
for(int row=0; row<rasterRows; row += blockSize)
{
int rowProcess;
if(row + blockSize < rasterRows)
{
rowProcess = blockSize;
}
else
{
rowProcess = rasterRows - row;
}
for(int col=0; col < rasterCols; col += blockSize)
{
int colProcess;
if(col + blockSize < rasterCols)
{
colProcess = blockSize;
}
else
{
colProcess = rasterCols - col;
}
double[] valueRasterValues = new double[rowProcess*colProcess];
bandValueRaster.ReadRaster(col, row, colProcess, rowProcess, valueRasterValues, colProcess,rowProcess, 0, 0);
}
}
}
Code Snippet: Read raster row by row using GDAL and C#
private static void ReadRasterRows(ref Dataset valueRaster)
{
Band bandValueRaster = valueRaster.GetRasterBand(1);
int rasterRows = valueRaster.RasterYSize;
int rasterCols = valueRaster.RasterXSize;
for(int row=0; row <rasterRows; row++)
{
double[] valueRasterValues = new double[rasterCols];
double[] zoneRasterValues = new double[rasterCols];
bandValueRaster.ReadRaster(0, row, rasterCols, 1, valueRasterValues, rasterCols, 1, 0, 0);
}
}

0 comments :
Post a Comment