Skip to content
Permalink
Browse files

Close gdal/ogr data sources when finished in dataItems implementation

  • Loading branch information
wonder-sk committed Aug 17, 2011
1 parent 42418b1 commit 22f5ba29e20973f4a50ca0cfd8d2dad670bb8c6e
Showing with 24 additions and 15 deletions.
  1. +17 −15 src/providers/gdal/qgsgdalprovider.cpp
  2. +7 −0 src/providers/ogr/qgsogrprovider.cpp
@@ -884,12 +884,12 @@ void QgsGdalProvider::computeMinMax( int theBandNo )
return;
}
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, theBandNo );
int bApproxOK=false;
int bApproxOK = false;
int bGotMin, bGotMax;
double adfMinMax[2];
adfMinMax[0] = GDALGetRasterMinimum( myGdalBand, &bGotMin );
adfMinMax[1] = GDALGetRasterMaximum( myGdalBand, &bGotMax );
if( ! ( bGotMin && bGotMax ) )
if ( !( bGotMin && bGotMax ) )
{
GDALComputeRasterMinMax( myGdalBand, TRUE, adfMinMax );
}
@@ -1838,7 +1838,7 @@ QgsRasterBandStats QgsGdalProvider::bandStatistics( int theBandNo )
{
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, theBandNo );
QgsRasterBandStats myRasterBandStats;
int bApproxOK=false;
int bApproxOK = false;
double pdfMin;
double pdfMax;
double pdfMean;
@@ -1847,26 +1847,26 @@ QgsRasterBandStats QgsGdalProvider::bandStatistics( int theBandNo )
myProg.type = ProgressHistogram;
myProg.provider = this;

// double myerval =
// GDALComputeRasterStatistics (
// myGdalBand, bApproxOK, &pdfMin, &pdfMax, &pdfMean, &pdfStdDev,
// progressCallback, &myProg ) ;
// double myerval =
// double myerval =
// GDALComputeRasterStatistics (
// myGdalBand, bApproxOK, &pdfMin, &pdfMax, &pdfMean, &pdfStdDev,
// progressCallback, &myProg ) ;
// double myerval =
// GDALGetRasterStatistics ( myGdalBand, bApproxOK, TRUE, &pdfMin, &pdfMax, &pdfMean, &pdfStdDev);
// double myerval =
// double myerval =
// GDALGetRasterStatisticsProgress ( myGdalBand, bApproxOK, TRUE, &pdfMin, &pdfMax, &pdfMean, &pdfStdDev,
// progressCallback, &myProg );
// progressCallback, &myProg );

// try to fetch the cached stats (bForce=FALSE)
CPLErr myerval =
GDALGetRasterStatistics ( myGdalBand, bApproxOK, FALSE, &pdfMin, &pdfMax, &pdfMean, &pdfStdDev);
CPLErr myerval =
GDALGetRasterStatistics( myGdalBand, bApproxOK, FALSE, &pdfMin, &pdfMax, &pdfMean, &pdfStdDev );

// if cached stats are not found, compute them
if ( CE_Warning == myerval )
{
myerval = GDALComputeRasterStatistics ( myGdalBand, bApproxOK,
&pdfMin, &pdfMax, &pdfMean, &pdfStdDev,
progressCallback, &myProg ) ;
myerval = GDALComputeRasterStatistics( myGdalBand, bApproxOK,
&pdfMin, &pdfMax, &pdfMean, &pdfStdDev,
progressCallback, &myProg ) ;
}

// if stats are found populate the QgsRasterBandStats object
@@ -2010,6 +2010,8 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
if ( !hDS )
return 0;

GDALClose( hDS );

QgsDebugMsg( "GdalDataset opened " + thePath );

QString name = info.fileName();
@@ -2288,7 +2288,10 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
int numLayers = OGR_DS_GetLayerCount( hDataSource );

if ( numLayers == 0 )
{
OGR_DS_Destroy( hDataSource );
return 0;
}

QgsDataCollectionItem * collection = 0;
if ( numLayers > 1 )
@@ -2352,10 +2355,14 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )

QgsOgrLayerItem * item = new QgsOgrLayerItem( collection ? collection : parentItem, name, path, layerUri, layerType );
if ( numLayers == 1 )
{
OGR_DS_Destroy( hDataSource );
return item;
}
collection->addChild( item );
}
collection->setPopulated();
OGR_DS_Destroy( hDataSource );
return collection;
}

0 comments on commit 22f5ba2

Please sign in to comment.
You can’t perform that action at this time.