From f6c018b3cae5c1348e003c29ec5a3cb4a5633a43 Mon Sep 17 00:00:00 2001 From: timlinux Date: Tue, 18 May 2004 22:58:49 +0000 Subject: [PATCH] Relax checking of raster filetype extensions to cater for filetypes where extension is unpredictable (e.g. grass). Now I use gdal to quickly check if a file is useable so pretty much anything gdal iscompile with should get through if you have chosen wildcard filter in add raster dialog. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@1428 c8812cc2-4d05-0410-92ff-de0c093fc19c --- src/qgisapp.cpp | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/src/qgisapp.cpp b/src/qgisapp.cpp index 3edefd76219..9cbdf9c288e 100644 --- a/src/qgisapp.cpp +++ b/src/qgisapp.cpp @@ -1410,13 +1410,40 @@ bool QgisApp::addRasterLayer(QStringList const &theFileNameQStringList) /** This helper checks to see whether the filename appears to be a valid raster file name */ bool QgisApp::isValidRasterFileName(QString theFileNameQString) { - QString name = theFileNameQString.lower(); - return (name.endsWith(".adf") || - name.endsWith(".asc") || - name.endsWith(".grd") || - name.endsWith(".img") || - name.endsWith(".tif") || name.endsWith(".png") || name.endsWith(".jpg") || name.endsWith(".dem") || name.endsWith(".ddf")) || - name.endsWith(".dt0"); + + GDALDatasetH myDataset; + GDALAllRegister(); + + + myDataset = GDALOpen( theFileNameQString, GA_ReadOnly ); + + if( myDataset == NULL ) + { + return false; + } + else + { + return true; + } + + /* + * This way is no longer a good idea because it does not + * cater for filetypes such as grass rasters that dont + * have a predictable file extension. + * + QString name = theFileNameQString.lower(); + return (name.endsWith(".adf") || + name.endsWith(".asc") || + name.endsWith(".grd") || + name.endsWith(".img") || + name.endsWith(".tif") || + name.endsWith(".png") || + name.endsWith(".jpg") || + name.endsWith(".dem") || + name.endsWith(".ddf")) || + name.endsWith(".dt0"); + +*/ } /** Overloaded of the above function provided for convenience that takes a qstring pointer */