@@ -267,36 +267,20 @@ bool QgsRasterLayer::isValidRasterFileName(QString const & theFileNameQString)
267
267
{
268
268
return false ;
269
269
}
270
+ else if ( GDALGetRasterCount ( myDataset ) == 0 )
271
+ {
272
+ GDALClose ( myDataset );
273
+ myDataset = NULL ;
274
+ return false ;
275
+ }
270
276
else
271
277
{
272
278
GDALClose (myDataset);
273
279
return true ;
274
280
}
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
- */
294
281
}
295
282
296
283
297
-
298
-
299
-
300
284
// ////////////////////////////////////////////////////////
301
285
//
302
286
// Non Static methods now....
@@ -421,6 +405,16 @@ bool QgsRasterLayer::readFile( QString const & fileName )
421
405
422
406
// check f this file has pyramids
423
407
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
+ }
424
418
if ( GDALGetOverviewCount (myGDALBand) > 0 )
425
419
{
426
420
hasPyramidsFlag=true ;
0 commit comments