Skip to content
Permalink
Browse files
improve error propagation for raster open errors (#1040)
git-svn-id: http://svn.osgeo.org/qgis/trunk@8694 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
warmerdam committed Jun 30, 2008
1 parent adfe7b8 commit 25e8ed76fddee8237c2bfdf8b13ea3677e69715e
Showing with 29 additions and 3 deletions.
  1. +8 −1 src/app/qgisapp.cpp
  2. +15 −1 src/core/raster/qgsrasterlayer.cpp
  3. +6 −1 src/core/raster/qgsrasterlayer.h
@@ -3126,6 +3126,7 @@ void QgisApp::openProject(const QString & fileName)
bool QgisApp::openLayer(const QString & fileName)
{
QFileInfo fileInfo(fileName);

// try to load it as raster
QgsMapLayer* ok = NULL;
CPLPushErrorHandler(CPLQuietErrorHandler);
@@ -5323,7 +5324,9 @@ bool QgisApp::addRasterLayers(QStringList const &theFileNameQStringList, bool gu
myIterator != theFileNameQStringList.end();
++myIterator)
{
if (QgsRasterLayer::isValidRasterFileName(*myIterator))
QString errMsg;

if (QgsRasterLayer::isValidRasterFileName(*myIterator,errMsg))
{
QFileInfo myFileInfo(*myIterator);
// get the directory the .adf file was in
@@ -5356,6 +5359,10 @@ bool QgisApp::addRasterLayers(QStringList const &theFileNameQStringList, bool gu
if(guiWarning)
{
QString msg(*myIterator + tr(" is not a supported raster data source"));

if( errMsg.size() > 0 )
msg += "\n" + errMsg;

QMessageBox::critical(this, tr("Unsupported Data Source"), msg);
}
returnValue = false;
@@ -255,22 +255,28 @@ void QgsRasterLayer::registerGdalDrivers()


/** This helper checks to see whether the filename appears to be a valid raster file name */
bool QgsRasterLayer::isValidRasterFileName(QString const & theFileNameQString)
bool QgsRasterLayer::isValidRasterFileName(QString const & theFileNameQString,
QString & retErrMsg )
{

GDALDatasetH myDataset;
registerGdalDrivers();

CPLErrorReset();

//open the file using gdal making sure we have handled locale properly
myDataset = GDALOpen( QFile::encodeName(theFileNameQString).constData(), GA_ReadOnly );
if( myDataset == NULL )
{
if( CPLGetLastErrorNo() != CPLE_OpenFailed )
retErrMsg = CPLGetLastErrorMsg();
return false;
}
else if( GDALGetRasterCount( myDataset ) == 0 )
{
GDALClose( myDataset );
myDataset = NULL;
retErrMsg = "This raster file has no bands and is invalid as a raster layer.";
return false;
}
else
@@ -280,6 +286,14 @@ bool QgsRasterLayer::isValidRasterFileName(QString const & theFileNameQString)
}
}

bool QgsRasterLayer::isValidRasterFileName(QString const & theFileNameQString)

{
QString retErrMsg;

return isValidRasterFileName( theFileNameQString, retErrMsg);
}


//////////////////////////////////////////////////////////
//
@@ -189,7 +189,12 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
static void registerGdalDrivers();

/** This helper checks to see whether the filename appears to be a valid
raster file name */
raster file name. If the filename looks like it could be valid,
but some sort of error occurs in processing the file, the error is
returned in retError. */
static bool isValidRasterFileName(const QString & theFileNameQString,
QString &retError );

static bool isValidRasterFileName(const QString & theFileNameQString);

//

0 comments on commit 25e8ed7

Please sign in to comment.