Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[BUGFIX] Relative path for GDAL subdataset
For some raster layer, the datasource is not stored in the project as relative.
 It's the case for NETCDF, HDF4, HDF5, NITF and RADARSAT2 raster format.

This patch keeps the datasource structure but updates the path part.

It will be interesting to backport it to 2.8 branch.
  • Loading branch information
rldhont committed May 13, 2015
1 parent a0017f9 commit 1e08bc0
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/core/qgsmaplayer.cpp
Expand Up @@ -46,6 +46,7 @@
#include "qgsrectangle.h"
#include "qgsvectorlayer.h"


QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,
QString lyrname,
QString source ) :
Expand Down Expand Up @@ -291,6 +292,34 @@ bool QgsMapLayer::readLayerXML( const QDomElement& layerElement )
}
// <<< BACKWARD COMPATIBILITY < 1.9
}
else if ( provider == "gdal" )
{
QStringList theURIParts = mDataSource.split( ":" );
if ( theURIParts[0] == "NETCDF" )
{
QString src = theURIParts[1];
src.replace( "\"", "" );
src = QgsProject::instance()->readPath( src );
theURIParts[1] = "\"" + src + "\"";
}
else if ( theURIParts[0] == "HDF4_SDS" )
{
theURIParts[2] = QgsProject::instance()->readPath( theURIParts[2] );
}
else if ( theURIParts[0] == "HDF5" )
{
theURIParts[1] = QgsProject::instance()->readPath( theURIParts[1] );
}
else if ( theURIParts[0] == "NITF_IM" )
{
theURIParts[2] = QgsProject::instance()->readPath( theURIParts[2] );
}
else if ( theURIParts[0] == "RADARSAT_2_CALIB" )
{
theURIParts[2] = QgsProject::instance()->readPath( theURIParts[2] );
}
mDataSource = theURIParts.join( ":" );
}
else
{
mDataSource = QgsProject::instance()->readPath( mDataSource );
Expand Down Expand Up @@ -488,6 +517,39 @@ bool QgsMapLayer::writeLayerXML( QDomElement& layerElement, QDomDocument& docume
urlDest.setQueryItems( urlSource.queryItems() );
src = QString::fromAscii( urlDest.toEncoded() );
}
else if ( !vlayer )
{
QgsRasterLayer *rlayer = qobject_cast<QgsRasterLayer *>( this );
// Update path for subdataset
if ( rlayer && rlayer->providerType() == "gdal" )
{
QStringList theURIParts = src.split( ":" );
if ( theURIParts[0] == "NETCDF" )
{
src = theURIParts[1];
src.replace( "\"", "" );
src = QgsProject::instance()->writePath( src, relativeBasePath );
theURIParts[1] = "\"" + src + "\"";
}
else if ( theURIParts[0] == "HDF4_SDS" )
{
theURIParts[2] = QgsProject::instance()->writePath( theURIParts[2], relativeBasePath );
}
else if ( theURIParts[0] == "HDF5" )
{
theURIParts[1] = QgsProject::instance()->writePath( theURIParts[1], relativeBasePath );
}
else if ( theURIParts[0] == "NITF_IM" )
{
theURIParts[2] = QgsProject::instance()->writePath( theURIParts[2], relativeBasePath );
}
else if ( theURIParts[0] == "RADARSAT_2_CALIB" )
{
theURIParts[2] = QgsProject::instance()->writePath( theURIParts[2], relativeBasePath );
}
src = theURIParts.join( ":" );
}
}
else
{
src = QgsProject::instance()->writePath( src, relativeBasePath );
Expand Down

0 comments on commit 1e08bc0

Please sign in to comment.