mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
also handle writing of relative paths (followup 47cb75d; fixes #12823)
This commit is contained in:
parent
598563c05a
commit
e2e8c8708d
@ -292,58 +292,69 @@ bool QgsMapLayer::readLayerXML( const QDomElement& layerElement )
|
||||
}
|
||||
// <<< BACKWARD COMPATIBILITY < 1.9
|
||||
}
|
||||
else if ( provider == "gdal" && mDataSource.startsWith( "NETCDF:" ) )
|
||||
{
|
||||
// NETCDF:filename:variable
|
||||
// filename can be quoted with " as it can contain colons
|
||||
QRegExp r( "NETCDF:(.+):([^:]+)" );
|
||||
if ( r.exactMatch( mDataSource ) )
|
||||
{
|
||||
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 ( 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 ) )
|
||||
{
|
||||
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 ( 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 ) )
|
||||
{
|
||||
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 ( provider == "gdal" && mDataSource.contains( QRegExp( "^(NITF_IM|RADARSAT_2_CALIB):" ) ) )
|
||||
{
|
||||
// NITF_IM:0:filename
|
||||
// RADARSAT_2_CALIB:?:filename
|
||||
QRegExp r( "([^:]+):([^:]+):(.+)" );
|
||||
if ( r.exactMatch( mDataSource ) )
|
||||
{
|
||||
mDataSource = r.cap( 1 ) + ":" + r.cap( 2 ) + ":" + QgsProject::instance()->readPath( r.cap( 3 ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mDataSource = QgsProject::instance()->readPath( mDataSource );
|
||||
bool handled = false;
|
||||
|
||||
if ( provider == "gdal" )
|
||||
{
|
||||
if ( mDataSource.startsWith( "NETCDF:" ) )
|
||||
{
|
||||
// NETCDF:filename:variable
|
||||
// filename can be quoted with " as it can contain colons
|
||||
QRegExp r( "NETCDF:(.+):([^:]+)" );
|
||||
if ( r.exactMatch( mDataSource ) )
|
||||
{
|
||||
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 );
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
else if ( 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 ) )
|
||||
{
|
||||
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 );
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
else if ( mDataSource.startsWith( "HDF5:" ) )
|
||||
{
|
||||
// HDF5:file_name:subdataset
|
||||
// filename can be quoted with " as it can contain colons
|
||||
QRegExp r( "HDF5:(.+):([^:]+)" );
|
||||
if ( r.exactMatch( mDataSource ) )
|
||||
{
|
||||
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 );
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
else if ( mDataSource.contains( QRegExp( "^(NITF_IM|RADARSAT_2_CALIB):" ) ) )
|
||||
{
|
||||
// NITF_IM:0:filename
|
||||
// RADARSAT_2_CALIB:?:filename
|
||||
QRegExp r( "([^:]+):([^:]+):(.+)" );
|
||||
if ( r.exactMatch( mDataSource ) )
|
||||
{
|
||||
mDataSource = r.cap( 1 ) + ":" + r.cap( 2 ) + ":" + QgsProject::instance()->readPath( r.cap( 3 ) );
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( !handled )
|
||||
mDataSource = QgsProject::instance()->readPath( mDataSource );
|
||||
}
|
||||
|
||||
// Set the CRS from project file, asking the user if necessary.
|
||||
@ -538,42 +549,74 @@ 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 );
|
||||
bool handled = false;
|
||||
|
||||
if ( !vlayer )
|
||||
{
|
||||
QgsRasterLayer *rlayer = qobject_cast<QgsRasterLayer *>( this );
|
||||
// Update path for subdataset
|
||||
if ( rlayer && rlayer->providerType() == "gdal" )
|
||||
{
|
||||
if ( src.startsWith( "NETCDF:" ) )
|
||||
{
|
||||
// NETCDF:filename:variable
|
||||
// filename can be quoted with " as it can contain colons
|
||||
QRegExp r( "NETCDF:(.+):([^:]+)" );
|
||||
if ( r.exactMatch( src ) )
|
||||
{
|
||||
QString filename = r.cap( 1 );
|
||||
if ( filename.startsWith( '"' ) && filename.endsWith( '"' ) )
|
||||
filename = filename.mid( 1, filename.length() - 2 );
|
||||
src = "NETCDF:\"" + QgsProject::instance()->writePath( filename, relativeBasePath ) + "\":" + r.cap( 2 );
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
else if ( src.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( src ) )
|
||||
{
|
||||
QString filename = r.cap( 2 );
|
||||
if ( filename.startsWith( '"' ) && filename.endsWith( '"' ) )
|
||||
filename = filename.mid( 1, filename.length() - 2 );
|
||||
src = "HDF4_SDS:" + r.cap( 1 ) + ":\"" + QgsProject::instance()->writePath( filename, relativeBasePath ) + "\":" + r.cap( 3 );
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
else if ( src.startsWith( "HDF5:" ) )
|
||||
{
|
||||
// HDF5:file_name:subdataset
|
||||
// filename can be quoted with " as it can contain colons
|
||||
QRegExp r( "HDF5:(.+):([^:]+)" );
|
||||
if ( r.exactMatch( src ) )
|
||||
{
|
||||
QString filename = r.cap( 1 );
|
||||
if ( filename.startsWith( '"' ) && filename.endsWith( '"' ) )
|
||||
filename = filename.mid( 1, filename.length() - 2 );
|
||||
src = "HDF5:\"" + QgsProject::instance()->writePath( filename, relativeBasePath ) + "\":" + r.cap( 2 );
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
else if ( src.contains( QRegExp( "^(NITF_IM|RADARSAT_2_CALIB):" ) ) )
|
||||
{
|
||||
// NITF_IM:0:filename
|
||||
// RADARSAT_2_CALIB:?:filename
|
||||
QRegExp r( "([^:]+):([^:]+):(.+)" );
|
||||
if ( r.exactMatch( src ) )
|
||||
{
|
||||
src = r.cap( 1 ) + ":" + r.cap( 2 ) + ":" + QgsProject::instance()->writePath( r.cap( 3 ), relativeBasePath );
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( !handled )
|
||||
src = QgsProject::instance()->writePath( src, relativeBasePath );
|
||||
}
|
||||
|
||||
QDomText dataSourceText = document.createTextNode( src );
|
||||
|
Loading…
x
Reference in New Issue
Block a user