Skip to content

Commit ce706d1

Browse files
author
warmerdam
committed
do not accept band-less dataset as valid (#1040)
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8693 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent af1e475 commit ce706d1

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

src/core/raster/qgsrasterlayer.cpp

+16-22
Original file line numberDiff line numberDiff line change
@@ -267,36 +267,20 @@ bool QgsRasterLayer::isValidRasterFileName(QString const & theFileNameQString)
267267
{
268268
return false;
269269
}
270+
else if( GDALGetRasterCount( myDataset ) == 0 )
271+
{
272+
GDALClose( myDataset );
273+
myDataset = NULL;
274+
return false;
275+
}
270276
else
271277
{
272278
GDALClose(myDataset);
273279
return true;
274280
}
275-
276-
/*
277-
* This way is no longer a good idea because it does not
278-
* cater for filetypes such as grass rasters that dont
279-
* have a predictable file extension.
280-
*
281-
QString name = theFileNameQString.toLower();
282-
return (name.endsWith(".adf") ||
283-
name.endsWith(".asc") ||
284-
name.endsWith(".grd") ||
285-
name.endsWith(".img") ||
286-
name.endsWith(".tif") ||
287-
name.endsWith(".png") ||
288-
name.endsWith(".jpg") ||
289-
name.endsWith(".dem") ||
290-
name.endsWith(".ddf")) ||
291-
name.endsWith(".dt0");
292-
293-
*/
294281
}
295282

296283

297-
298-
299-
300284
//////////////////////////////////////////////////////////
301285
//
302286
// Non Static methods now....
@@ -421,6 +405,16 @@ bool QgsRasterLayer::readFile( QString const & fileName )
421405

422406
//check f this file has pyramids
423407
GDALRasterBandH myGDALBand = GDALGetRasterBand( mGdalDataset, 1 ); //just use the first band
408+
if (myGDALBand == NULL)
409+
{
410+
GDALDereferenceDataset(mGdalBaseDataset);
411+
mGdalBaseDataset = NULL;
412+
413+
GDALClose(mGdalDataset);
414+
mGdalDataset = NULL;
415+
mValid = FALSE;
416+
return false;
417+
}
424418
if( GDALGetOverviewCount(myGDALBand) > 0 )
425419
{
426420
hasPyramidsFlag=true;

0 commit comments

Comments
 (0)