Skip to content

Commit 04abf76

Browse files
committedApr 23, 2012
case insensitive vsizip/vsigzip support
1 parent c56491b commit 04abf76

File tree

4 files changed

+37
-40
lines changed

4 files changed

+37
-40
lines changed
 

‎src/providers/gdal/qgsgdaldataitems.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
116116
int scanZipSetting = settings.value( "/qgis/scanZipInBrowser", 1 ).toInt();
117117

118118
// allow normal files or VSIFILE items to pass
119-
if ( ! info.isFile() &&
120-
thePath.left( 8 ) != "/vsizip/" &&
121-
thePath.left( 9 ) != "/vsigzip/" )
119+
if ( !info.isFile() &&
120+
!thePath.startsWith( "/vsizip/" ) &&
121+
!thePath.startsWith( "/vsigzip/" ) )
122122
return 0;
123123

124124
// get supported extensions
@@ -131,16 +131,16 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
131131

132132
// skip *.aux.xml files (GDAL auxilary metadata files)
133133
// unless that extension is in the list (*.xml might be though)
134-
if ( thePath.right( 8 ).toLower() == ".aux.xml" &&
135-
extensions.indexOf( "aux.xml" ) < 0 )
134+
if ( thePath.endsWith( ".aux.xml", Qt::CaseInsensitive ) &&
135+
! extensions.contains( "aux.xml" ) )
136136
return 0;
137137

138138
// skip .tar.gz files
139-
if ( thePath.right( 7 ) == ".tar.gz" )
139+
if ( thePath.endsWith( ".tar.gz", Qt::CaseInsensitive ) )
140140
return 0;
141141

142142
// Filter files by extension
143-
if ( extensions.indexOf( info.suffix().toLower() ) < 0 )
143+
if ( !extensions.contains( info.suffix().toLower() ) )
144144
{
145145
bool matches = false;
146146
foreach( QString wildcard, wildcards )
@@ -157,7 +157,7 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
157157
}
158158

159159
// vsifile : depending on options we should just add the item without testing
160-
if ( thePath.left( 8 ) == "/vsizip/" )
160+
if ( thePath.startsWith( "/vsizip/" ) )
161161
{
162162
// if this is a /vsigzip/path.zip/file_inside_zip change the name
163163
if ( thePath != "/vsizip/" + parentItem->path() )
@@ -189,14 +189,14 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
189189

190190

191191
// try to open using VSIFileHandler
192-
if ( thePath.right( 4 ) == ".zip" )
192+
if ( thePath.endsWith( ".zip", Qt::CaseInsensitive ) )
193193
{
194-
if ( thePath.left( 8 ) != "/vsizip/" )
194+
if ( !thePath.startsWith( "/vsizip/" ) )
195195
thePath = "/vsizip/" + thePath;
196196
}
197-
else if ( thePath.right( 3 ) == ".gz" )
197+
else if ( thePath.endsWith( ".gz", Qt::CaseInsensitive ) )
198198
{
199-
if ( thePath.left( 9 ) != "/vsigzip/" )
199+
if ( !thePath.startsWith( "/vsigzip/" ) )
200200
thePath = "/vsigzip/" + thePath;
201201
}
202202

‎src/providers/gdal/qgsgdalprovider.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,15 @@ QgsGdalProvider::QgsGdalProvider( QString const & uri )
109109
// Try to open using VSIFileHandler (see qgsogrprovider.cpp)
110110
// TODO suppress error messages and report in debug, like in OGR provider
111111
// TODO use the file name of the file inside the zip, needs unzip.h
112-
if ( uri.right( 4 ) == ".zip" )
112+
if ( uri.endsWith( ".zip", Qt::CaseInsensitive ) )
113113
{
114-
if ( uri.left( 8 ) != "/vsizip/" )
114+
if ( !uri.startsWith( "/vsizip/" ) )
115115
setDataSourceUri( "/vsizip/" + uri );
116116
QgsDebugMsg( QString( "Trying /vsizip syntax, uri= %1" ).arg( dataSourceUri() ) );
117117
}
118-
else if ( uri.right( 3 ) == ".gz" )
118+
else if ( uri.endsWith( ".gz", Qt::CaseInsensitive ) )
119119
{
120-
if ( uri.left( 9 ) != "/vsigzip/" )
120+
if ( !uri.startsWith( "/vsigzip/" ) )
121121
setDataSourceUri( "/vsigzip/" + uri );
122122
QgsDebugMsg( QString( "Trying /vsigzip syntax, uri= %1" ).arg( dataSourceUri() ) );
123123
}
@@ -126,7 +126,7 @@ QgsGdalProvider::QgsGdalProvider( QString const & uri )
126126
mGdalBaseDataset = GDALOpen( TO8F( dataSourceUri() ), GA_ReadOnly );
127127

128128
CPLErrorReset();
129-
if ( mGdalBaseDataset == NULL )
129+
if ( !mGdalBaseDataset )
130130
{
131131
QgsDebugMsg( QString( "Cannot open GDAL dataset %1: %2" ).arg( dataSourceUri() ).arg( QString::fromUtf8( CPLGetLastErrorMsg() ) ) );
132132
return;
@@ -575,7 +575,7 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
575575
double xRes = theExtent.width() / thePixelWidth;
576576
double yRes = theExtent.height() / thePixelHeight;
577577

578-
// Find top, bottom rows and left, right column the raster extent covers
578+
// Find top, bottom rows and left, right column the raster extent covers
579579
// These are limits in target grid space
580580
int top = 0;
581581
int bottom = thePixelHeight - 1;
@@ -1869,23 +1869,23 @@ QGISEXTERN bool isValidRasterFileName( QString const & theFileNameQString, QStri
18691869

18701870
// Try to open using VSIFileHandler (see qgsogrprovider.cpp)
18711871
// TODO suppress error messages and report in debug, like in OGR provider
1872-
if ( fileName.right( 4 ) == ".zip" )
1872+
if ( fileName.endsWith( ".zip", Qt::CaseInsensitive ) )
18731873
{
1874-
if ( fileName.left( 8 ) != "/vsizip/" )
1874+
if ( !fileName.startsWith( "/vsizip/" ) )
18751875
fileName = "/vsizip/" + fileName;
18761876
QgsDebugMsg( QString( "Trying /vsizip syntax, fileName= %1" ).arg( fileName ) );
18771877
}
1878-
if ( fileName.right( 3 ) == ".gz" )
1878+
if ( fileName.endsWith( ".gz", Qt::CaseInsensitive ) )
18791879
{
1880-
if ( fileName.left( 9 ) != "/vsigzip/" )
1880+
if ( !fileName.startsWith( "/vsigzip/" ) )
18811881
fileName = "/vsigzip/" + fileName;
18821882
QgsDebugMsg( QString( "Trying /vsigzip syntax, fileName= %1" ).arg( fileName ) );
18831883
}
18841884

18851885
//open the file using gdal making sure we have handled locale properly
18861886
//myDataset = GDALOpen( QFile::encodeName( theFileNameQString ).constData(), GA_ReadOnly );
18871887
myDataset = GDALOpen( TO8F( fileName ), GA_ReadOnly );
1888-
if ( myDataset == NULL )
1888+
if ( !myDataset )
18891889
{
18901890
if ( CPLGetLastErrorNo() != CPLE_OpenFailed )
18911891
retErrMsg = QString::fromUtf8( CPLGetLastErrorMsg() );

‎src/providers/ogr/qgsogrdataitems.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,9 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
235235
int scanZipSetting = settings.value( "/qgis/scanZipInBrowser", 1 ).toInt();
236236

237237
// allow normal files or VSIFILE items to pass
238-
if ( ! info.isFile() &&
239-
thePath.left( 8 ) != "/vsizip/" &&
240-
thePath.left( 9 ) != "/vsigzip/" )
238+
if ( !info.isFile() &&
239+
!thePath.startsWith( "/vsizip/" ) &&
240+
!thePath.startsWith( "/vsigzip/" ) )
241241
return 0;
242242

243243
QStringList myExtensions = fileExtensions();
@@ -282,11 +282,10 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
282282
}
283283

284284
// vsifile : depending on options we should just add the item without testing
285-
if ( thePath.left( 8 ) == "/vsizip/" )
285+
if ( thePath.startsWith( "/vsizip/" ) )
286286
{
287287
// if this is a /vsigzip/path.zip/file_inside_zip change the name
288-
if ( thePath.left( 8 ) == "/vsizip/" &&
289-
thePath != "/vsizip/" + parentItem->path() )
288+
if ( thePath != "/vsizip/" + parentItem->path() )
290289
{
291290
name = thePath;
292291
name = name.replace( "/vsizip/" + parentItem->path() + "/", "" );
@@ -310,14 +309,14 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
310309
}
311310

312311
// try to open using VSIFileHandler
313-
if ( thePath.right( 4 ) == ".zip" )
312+
if ( thePath.endsWith( ".zip", Qt::CaseInsensitive ) )
314313
{
315-
if ( thePath.left( 8 ) != "/vsizip/" )
314+
if ( !thePath.startsWith( "/vsizip/" ) )
316315
thePath = "/vsizip/" + thePath;
317316
}
318-
else if ( thePath.right( 3 ) == ".gz" )
317+
else if ( thePath.endsWith( ".gz", Qt::CaseInsensitive ) )
319318
{
320-
if ( thePath.left( 9 ) != "/vsigzip/" )
319+
if ( !thePath.startsWith( "/vsigzip/" ) )
321320
thePath = "/vsigzip/" + thePath;
322321
}
323322

‎src/providers/ogr/qgsogrprovider.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,18 +264,18 @@ QgsOgrProvider::QgsOgrProvider( QString const & uri )
264264

265265
// Try to open using VSIFileHandler
266266
// see http://trac.osgeo.org/gdal/wiki/UserDocs/ReadInZip
267-
if ( mFilePath.right( 4 ) == ".zip" )
267+
if ( mFilePath.endsWith( ".zip", Qt::CaseInsensitive ) )
268268
{
269269
// GDAL>=1.8.0 has write support for zip, but read and write operations
270270
// cannot be interleaved, so for now just use read-only.
271271
openReadOnly = true;
272-
if ( mFilePath.left( 8 ) != "/vsizip/" )
272+
if ( !mFilePath.startsWith( "/vsizip/" ) )
273273
mFilePath = "/vsizip/" + mFilePath;
274274
QgsDebugMsg( QString( "Trying /vsizip syntax, mFilePath= %1" ).arg( mFilePath ) );
275275
}
276-
else if ( mFilePath.right( 3 ) == ".gz" )
276+
else if ( mFilePath.endsWith( ".gz", Qt::CaseInsensitive ) )
277277
{
278-
if ( mFilePath.left( 9 ) != "/vsigzip/" )
278+
if ( !mFilePath.startsWith( "/vsigzip/" ) )
279279
mFilePath = "/vsigzip/" + mFilePath;
280280
QgsDebugMsg( QString( "Trying /vsigzip syntax, mFilePath= %1" ).arg( mFilePath ) );
281281
}
@@ -287,12 +287,11 @@ QgsOgrProvider::QgsOgrProvider( QString const & uri )
287287
CPLSetConfigOption( "OGR_ORGANIZE_POLYGONS", "ONLY_CCW" ); // "SKIP" returns MULTIPOLYGONs for multiringed POLYGONs
288288

289289
// first try to open in update mode (unless specified otherwise)
290-
if ( ! openReadOnly )
290+
if ( !openReadOnly )
291291
ogrDataSource = OGROpen( TO8F( mFilePath ), true, &ogrDriver );
292292

293293
if ( !ogrDataSource )
294294
{
295-
296295
QgsDebugMsg( "OGR failed to opened in update mode, trying in read-only mode" );
297296

298297
// try to open read-only
@@ -305,7 +304,6 @@ QgsOgrProvider::QgsOgrProvider( QString const & uri )
305304

306305
if ( ogrDataSource )
307306
{
308-
309307
QgsDebugMsg( "OGR opened using Driver " + QString( OGR_Dr_GetName( ogrDriver ) ) );
310308

311309
ogrDriverName = OGR_Dr_GetName( ogrDriver );

4 commit comments

Comments
 (4)

etiennesky commented on Apr 24, 2012

@etiennesky
Contributor

goof thinking ! have you looked at my improvements and tests in pull request 130 ?

timlinux commented on Apr 24, 2012

@timlinux
Member

etiennesky commented on Apr 24, 2012

@etiennesky
Contributor

I think github notice emails are not always working...

If you want I can patch that pull request with these changes by Jef

etiennesky commented on Apr 24, 2012

@etiennesky
Contributor

it doesn't apply cleanly after Jurgen's mods - will create a new pull request

Please sign in to comment.