[gdal-dev] Proposed Block iterator API
jramm
jamessramm at gmail.com
Sun Nov 22 03:27:53 PST 2015
Yes this would be incredibly useful. We typically process >100GB rasters and
so iterating in 'windows' is a must for us.
We have typically implemented a solution outside of GDAL, with a 'next'
function that looks something like this:
int RasterWindow::next()
{
static int windowNoX = -1;
static int windowNoY = 0;
// Initialise the size of the window read
curSizeX = windowSize;
curSizeY = windowSize;
// Check which window number we are on
if (((windowNoY + 1) >= nY) && ((windowNoX + 1) >= nX))
{
// All windows have been read
return 1;
}
// We have reached the end of a row (x) of windows
else if ((windowNoX + 1) >= nX)
{
windowNoX = 0;
windowNoY += 1;
}
// There are still pixels left on the row...
else
{
windowNoX += 1;
}
// Calculate the pixel offsets
xOff = windowNoX * windowSize;
yOff = windowNoY * windowSize;
// Correct the current window size to make sure it won't run off the edge
of the raster
if (xOff + windowSize > RasterSizeX)
{
curSizeX = RasterSizeX - xOff;
}
if (yOff + windowSize > RasterSizeY)
{
curSizeY = RasterSizeY - yOff;
}
return 0;
}
It allows us to read more (or less) than the 'natural' block size (if
necessary) so we can send big lumps of data off for processing on a GPU.
For convenience and completeness, it would be helpful if the GetNext
function would optionally take a buffer which, if present, would be
populated with the pixel values, negating the need for a line of boiler
plate to read the values.
Another (possibly?) useful component could be some sort of pixel iterator.
For smaller/non-parallel processes, after reading a block we then loop over
the pixels, often with some boiler plate code to pull out the array indices
for various purposes:
uint32_t i, j, iGlobal, jGlobal;
for(pixelCount = 0 ; pixelCount < nPixels ; pixelCount++)
{
i = pixelCount % currentWindowSizeX;
j = (pixelCount - i) / currentWindowSizeX;
iGlobal = i + nXoff;
jGlobal = j + nYoff;
}
A further function which would take in the desired block size and handle
reading the blocks, allocating buffers etc behind the scenes and then simply
return individual pixels & indices would be quite interesting.
int GDALBlockIteratorGetNextPixel(GDALBlockIteratorH hIter, void *pixel, int
*i, int *j, int *iGlobal, int *jGlobal);
--
View this message in context: http://osgeo-org.1560.x6.nabble.com/gdal-dev-Proposed-Block-iterator-API-tp5237743p5237882.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.
More information about the gdal-dev
mailing list