Skip to content
Permalink
Browse files

fix relative path support for gdal layers (fixes #12823)

  • Loading branch information
jef-n committed May 26, 2015
1 parent 205daae commit 47cb75dd6f8c3d0908383f021597b5627fc0b874
Showing with 46 additions and 25 deletions.
  1. +46 −25 src/core/qgsmaplayer.cpp
@@ -49,13 +49,13 @@

QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,
QString lyrname,
QString source ) :
mValid( false ), // assume the layer is invalid
mDataSource( source ),
mLayerOrigName( lyrname ), // store the original name
mID( "" ),
mLayerType( type ),
mBlendMode( QPainter::CompositionMode_SourceOver ) // Default to normal blending
QString source )
: mValid( false ) // assume the layer is invalid
, mDataSource( source )
, mLayerOrigName( lyrname ) // store the original name
, mID( "" )
, mLayerType( type )
, mBlendMode( QPainter::CompositionMode_SourceOver ) // Default to normal blending
, mLegend( 0 )
, mStyleManager( new QgsMapLayerStyleManager( this ) )
{
@@ -292,33 +292,54 @@ bool QgsMapLayer::readLayerXML( const QDomElement& layerElement )
}
// <<< BACKWARD COMPATIBILITY < 1.9
}
else if ( provider == "gdal" )
else if ( provider == "gdal" && mDataSource.startsWith( "NETCDF:" ) )
{
QStringList theURIParts = mDataSource.split( ":" );
if ( theURIParts[0] == "NETCDF" )
// NETCDF:filename:variable
// filename can be quoted with " as it can contain colons
QRegExp r( "NETCDF:(.+):([^:]+)" );
if ( r.exactMatch( mDataSource ) )
{
QString src = theURIParts[1];
src.replace( "\"", "" );
src = QgsProject::instance()->readPath( src );
theURIParts[1] = "\"" + src + "\"";
QString filename = r.cap( 1 );
if ( filename.startsWith( '"' ) && filename.endsWith( '"' ) )
filename = filename.mid( 1, filename.length() - 2 );
mDataSource = "NETCDF:\"" + QgsProject::instance()->readPath( filename ) + "\":" + r.cap( 2 );
}
else if ( theURIParts[0] == "HDF4_SDS" )
{
theURIParts[2] = QgsProject::instance()->readPath( theURIParts[2] );
}
else if ( theURIParts[0] == "HDF5" )
}
else if ( provider == "gdal" && mDataSource.startsWith( "HDF4_SDS:" ) )
{
// HDF4_SDS:subdataset_type:file_name:subdataset_index
// filename can be quoted with " as it can contain colons
QRegExp r( "HDF4_SDS:([^:]+):(.+):([^:]+)" );
if ( r.exactMatch( mDataSource ) )
{
theURIParts[1] = QgsProject::instance()->readPath( theURIParts[1] );
QString filename = r.cap( 2 );
if ( filename.startsWith( '"' ) && filename.endsWith( '"' ) )
filename = filename.mid( 1, filename.length() - 2 );
mDataSource = "HDF4_SDS:" + r.cap( 1 ) + ":\"" + QgsProject::instance()->readPath( filename ) + "\":" + r.cap( 3 );
}
else if ( theURIParts[0] == "NITF_IM" )
}
else if ( provider == "gdal" && mDataSource.startsWith( "HDF5:" ) )
{
// HDF5:file_name:subdataset
// filename can be quoted with " as it can contain colons
QRegExp r( "HDF5:(.+):([^:]+)" );
if ( r.exactMatch( mDataSource ) )
{
theURIParts[2] = QgsProject::instance()->readPath( theURIParts[2] );
QString filename = r.cap( 1 );
if ( filename.startsWith( '"' ) && filename.endsWith( '"' ) )
filename = filename.mid( 1, filename.length() - 2 );
mDataSource = "HDF5:\"" + QgsProject::instance()->readPath( filename ) + "\":" + r.cap( 2 );
}
else if ( theURIParts[0] == "RADARSAT_2_CALIB" )
}
else if ( provider == "gdal" && mDataSource.contains( QRegExp( "^(NITF_IM|RADARSAT_2_CALIB):" ) ) )
{
// NITF_IM:0:filename
// RADARSAT_2_CALIB:?:filename
QRegExp r( "([^:]+):([^:]+):(.+)" );
if ( r.exactMatch( mDataSource ) )
{
theURIParts[2] = QgsProject::instance()->readPath( theURIParts[2] );
mDataSource = r.cap( 1 ) + ":" + r.cap( 2 ) + ":" + QgsProject::instance()->readPath( r.cap( 3 ) );
}
mDataSource = theURIParts.join( ":" );
}
else
{

3 comments on commit 47cb75d

@nyalldawson

This comment has been minimized.

Copy link
Collaborator

@nyalldawson nyalldawson replied May 26, 2015

@jef-n should this fix be backported? The original commit which triggered this was backported to 2.8 so that branch also suffers this bug

@rldhont

This comment has been minimized.

Copy link
Contributor

@rldhont rldhont replied May 26, 2015

Does the code between the line 520-550 should be updated? like in my commit 350bbb7 ?

@jef-n

This comment has been minimized.

Copy link
Member Author

@jef-n jef-n replied May 26, 2015

@nyalldawson sure - but I'll wait some time before I merge

Please sign in to comment.