[Gdal-dev] featureDataset->RasterIO efficient pixel value reading
question
Andrew Finley
afinley at gis.umn.edu
Tue Jan 18 23:24:30 EST 2005
Hi Frank,
Some time ago, you helped me out with some code to speed up multi-band
image pixel value access. I was using rasterIO to read one pixel at a
time. You suggested the code below to grab a larger block (xsize*bands):
// Make sure that lineBuf holds one whole line of data.
float *lineBuf;
int xsize = featureDataset->GetRasterXSize();
int ysize = featureDataset->GetRasterYSize();
int bandCount = featureDataset->GetRasterCount();
lineBuf = (float *) CPLMalloc(xsize * bandCount);
//every row loop
for (int row = 0; row < featureDataset->GetRasterYSize(); row++){
featureDataset->RasterIO( GF_Read, 0, row, xsize, 1,
lineBuf, xsize, 1, GDT_Float32,
bandCount, NULL,
4 * bandCount, 0, 4 );
// every pixel in row.
for (int col = 0; col < featureDataset->GetRasterXSize(); col++){
float *targetBandVec = lineBuf + col;
... perform classification ..
}
}
I'm having some trouble understanding the parameters that go into
featureDataset rasterIO and how it packs the data into the row lineBuf.
What are the values of 4 you put in the RasterIO above? Could you take me
one step further in the above example, so I can see how the pixel bands are
layed out in the lineBuf. I took a shot below:
// Make sure that lineBuf holds one whole line of data.
float *lineBuf;
int xsize = featureDataset->GetRasterXSize();
int ysize = featureDataset->GetRasterYSize();
int bandCount = featureDataset->GetRasterCount();
lineBuf = (float *) CPLMalloc(sizeof(float)*xsize*bandCount);
//every row loop
for (int row = 0; row < featureDataset->GetRasterYSize(); row++){
featureDataset->RasterIO( GF_Read, 0, row, xsize, 1, lineBuf, xsize, 1,
GDT_Float32, bandCount, NULL, 4 * bandCount, 0, 4 );
//every pixel in row.
for (int col = 0; col < featureDataset->GetRasterXSize(); col++){
float *targetBandVec = lineBuf + col;
//every band value in pixel (i.e., each cout row is a pixel and row
elements are specific band values in that pixel)
//I know this part is wrong.
for(int band = 0; band < bandCount; band++)
cout << targetBandVec[band] <<" ";
cout << endl;
}
}
As always thanks for your time, I really appreciate your help.
-andy
More information about the Gdal-dev
mailing list