|
49 | 49 |
|
50 | 50 | QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,
|
51 | 51 | QString lyrname,
|
52 |
| - QString source ) : |
53 |
| - mValid( false ), // assume the layer is invalid |
54 |
| - mDataSource( source ), |
55 |
| - mLayerOrigName( lyrname ), // store the original name |
56 |
| - mID( "" ), |
57 |
| - mLayerType( type ), |
58 |
| - mBlendMode( QPainter::CompositionMode_SourceOver ) // Default to normal blending |
| 52 | + QString source ) |
| 53 | + : mValid( false ) // assume the layer is invalid |
| 54 | + , mDataSource( source ) |
| 55 | + , mLayerOrigName( lyrname ) // store the original name |
| 56 | + , mID( "" ) |
| 57 | + , mLayerType( type ) |
| 58 | + , mBlendMode( QPainter::CompositionMode_SourceOver ) // Default to normal blending |
59 | 59 | , mLegend( 0 )
|
60 | 60 | , mStyleManager( new QgsMapLayerStyleManager( this ) )
|
61 | 61 | {
|
@@ -292,33 +292,54 @@ bool QgsMapLayer::readLayerXML( const QDomElement& layerElement )
|
292 | 292 | }
|
293 | 293 | // <<< BACKWARD COMPATIBILITY < 1.9
|
294 | 294 | }
|
295 |
| - else if ( provider == "gdal" ) |
| 295 | + else if ( provider == "gdal" && mDataSource.startsWith( "NETCDF:" ) ) |
296 | 296 | {
|
297 |
| - QStringList theURIParts = mDataSource.split( ":" ); |
298 |
| - if ( theURIParts[0] == "NETCDF" ) |
| 297 | + // NETCDF:filename:variable |
| 298 | + // filename can be quoted with " as it can contain colons |
| 299 | + QRegExp r( "NETCDF:(.+):([^:]+)" ); |
| 300 | + if ( r.exactMatch( mDataSource ) ) |
299 | 301 | {
|
300 |
| - QString src = theURIParts[1]; |
301 |
| - src.replace( "\"", "" ); |
302 |
| - src = QgsProject::instance()->readPath( src ); |
303 |
| - theURIParts[1] = "\"" + src + "\""; |
| 302 | + QString filename = r.cap( 1 ); |
| 303 | + if ( filename.startsWith( '"' ) && filename.endsWith( '"' ) ) |
| 304 | + filename = filename.mid( 1, filename.length() - 2 ); |
| 305 | + mDataSource = "NETCDF:\"" + QgsProject::instance()->readPath( filename ) + "\":" + r.cap( 2 ); |
304 | 306 | }
|
305 |
| - else if ( theURIParts[0] == "HDF4_SDS" ) |
306 |
| - { |
307 |
| - theURIParts[2] = QgsProject::instance()->readPath( theURIParts[2] ); |
308 |
| - } |
309 |
| - else if ( theURIParts[0] == "HDF5" ) |
| 307 | + } |
| 308 | + else if ( provider == "gdal" && mDataSource.startsWith( "HDF4_SDS:" ) ) |
| 309 | + { |
| 310 | + // HDF4_SDS:subdataset_type:file_name:subdataset_index |
| 311 | + // filename can be quoted with " as it can contain colons |
| 312 | + QRegExp r( "HDF4_SDS:([^:]+):(.+):([^:]+)" ); |
| 313 | + if ( r.exactMatch( mDataSource ) ) |
310 | 314 | {
|
311 |
| - theURIParts[1] = QgsProject::instance()->readPath( theURIParts[1] ); |
| 315 | + QString filename = r.cap( 2 ); |
| 316 | + if ( filename.startsWith( '"' ) && filename.endsWith( '"' ) ) |
| 317 | + filename = filename.mid( 1, filename.length() - 2 ); |
| 318 | + mDataSource = "HDF4_SDS:" + r.cap( 1 ) + ":\"" + QgsProject::instance()->readPath( filename ) + "\":" + r.cap( 3 ); |
312 | 319 | }
|
313 |
| - else if ( theURIParts[0] == "NITF_IM" ) |
| 320 | + } |
| 321 | + else if ( provider == "gdal" && mDataSource.startsWith( "HDF5:" ) ) |
| 322 | + { |
| 323 | + // HDF5:file_name:subdataset |
| 324 | + // filename can be quoted with " as it can contain colons |
| 325 | + QRegExp r( "HDF5:(.+):([^:]+)" ); |
| 326 | + if ( r.exactMatch( mDataSource ) ) |
314 | 327 | {
|
315 |
| - theURIParts[2] = QgsProject::instance()->readPath( theURIParts[2] ); |
| 328 | + QString filename = r.cap( 1 ); |
| 329 | + if ( filename.startsWith( '"' ) && filename.endsWith( '"' ) ) |
| 330 | + filename = filename.mid( 1, filename.length() - 2 ); |
| 331 | + mDataSource = "HDF5:\"" + QgsProject::instance()->readPath( filename ) + "\":" + r.cap( 2 ); |
316 | 332 | }
|
317 |
| - else if ( theURIParts[0] == "RADARSAT_2_CALIB" ) |
| 333 | + } |
| 334 | + else if ( provider == "gdal" && mDataSource.contains( QRegExp( "^(NITF_IM|RADARSAT_2_CALIB):" ) ) ) |
| 335 | + { |
| 336 | + // NITF_IM:0:filename |
| 337 | + // RADARSAT_2_CALIB:?:filename |
| 338 | + QRegExp r( "([^:]+):([^:]+):(.+)" ); |
| 339 | + if ( r.exactMatch( mDataSource ) ) |
318 | 340 | {
|
319 |
| - theURIParts[2] = QgsProject::instance()->readPath( theURIParts[2] ); |
| 341 | + mDataSource = r.cap( 1 ) + ":" + r.cap( 2 ) + ":" + QgsProject::instance()->readPath( r.cap( 3 ) ); |
320 | 342 | }
|
321 |
| - mDataSource = theURIParts.join( ":" ); |
322 | 343 | }
|
323 | 344 | else
|
324 | 345 | {
|
|
0 commit comments