[gdal-dev] loading many files with C API
Yann Chemin
yann.chemin at gmail.com
Mon Nov 24 08:14:30 EST 2008
Hi again,
the first problem was an input output argv[] confusion. I can load 350
files and it is OK. I may have another problem at the pixel level, but
in case i'll start a new thread.
Thank you Ivan for your suggestion, it would be meaningful indeed to do that.
void usage()
{
printf( "-----------------------------------------------------------\n");
printf( "--Calculate the frequency of occurrence of an event--------\n");
printf( "-----------------------------------------------------------\n");
printf( "./freq outFREQ infile1[ infile2 infile3 ...] \n");
printf( "-----------------------------------------------------------\n");
return;
}
int main( int argc, char *argv[] )
{
if( argc < 5 ) {
usage();
return 1;
}
int i, row, col;
char *in[MAXFILES];
char *out;
int imgs_per_year;
int n_imgs;
int n_null_pix;
GDALDatasetH hDataset[MAXFILES+1];
GDALAllRegister();
GDALDriverH hDriver[MAXFILES+1];
GDALRasterBandH hBand[MAXFILES+1];
float *pafScanline[MAXFILES+1];
int nXSize1, nYSize1;
out = argv[1];
//Loading input files
n_imgs = argc - 2;
for (i=0;i<n_imgs;i++){
printf("%i / %i %s\n",i,n_imgs,argv[i+2]);
in[i] = argv[i+2];
hDataset[i] = GDALOpen(in[i],GA_ReadOnly);
hDriver[i] = GDALGetDatasetDriver(hDataset[i]);
hBand[i] = GDALGetRasterBand(hDataset[i],1);
nXSize1 = GDALGetRasterBandXSize(hBand[0]);
pafScanline[i] = (float *) CPLMalloc(sizeof(float)*nXSize1);
}
printf("Passed 1\n");
nYSize1 = GDALGetRasterBandYSize(hBand[0]);
//Creating output file
hDataset[n_imgs] = GDALCreateCopy( hDriver[0], out,
hDataset[0],FALSE,NULL,NULL,NULL);
hBand[n_imgs] = GDALGetRasterBand(hDataset[n_imgs],1);
pafScanline[n_imgs] = (float *) CPLMalloc(sizeof(float)*nXSize1);
////////////////// LOAD Pixels and process from there
/////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Thanks
Yann
2008/11/25 Ivan Lucena <ivan.lucena at pmldnet.com>:
> Yann, Frank,
>
> Another thing to considerer is that any process you might want to do on that
> file storage option will be way much slower than if it was done in a multi
> band, tiled, interleaved by pixel format.
>
> That is my experience,
>
> Ivan
>
> Frank Warmerdam wrote:
>>
>> Yann Chemin wrote:
>>>
>>> Hello,
>>>
>>> I need to load about 400 files with the C API to work on each pixel
>>> temporal dimension.
>>>
>>> I would like to make a look to load them but fail so far...
>>>
>>> GDALDatasetH hDataset[MAXFILES];
>>> GDALAllRegister();
>>> GDALDriverH hDriver[MAXFILES];
>>> GDALRasterBandH hBand[MAXFILES];
>>> float *pafScanline[MAXFILES];
>>> int nXSize1,nYSize1;
>>>
>>> //loading input files
>>> for(i=0;i<n_imgs;i++){
>>> in[i] = argv[i+1];
>>> hDataset[i] = GDALOpen(in[i];GA_ReadOnly);
>>> hDriver[i] = GDALDatasetDriver(hDataset[i]);
>>> hBand[i] = GDALGetRasterBand(hDataset[i],1);
>>> nXSize1 = GDALGetRasterBandXSize(hBand[0]);
>>> pafScanline[i] = (float *) CPLMalloc(sizeof(float)*nXSize1);
>>> }
>>>
>>> it mentions error 10: 'hDataset' is NULL in 'GDALGetDatasetDriver'
>>
>> Yann,
>>
>> Is that the first error reported? Does it occur for i==0 or much later
>> (perhaps around the 250th file)? Many operating systems have a limit
>> on the number of files that can be open at once, in some cases around
>> 256.
>>
>> Best regards,
>
>
--
Yann Chemin
International Rice Research Institute
Office: http://www.irri.org/gis
Perso: http://www.freewebs.com/ychemin
YiKingDo: http://yikingdo.unblog.fr/
More information about the gdal-dev
mailing list