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,7 +292,13 @@ bool QgsMapLayer::readLayerXML( const QDomElement& layerElement )
|
|||||||
}
|
}
|
||||||
// <<< BACKWARD COMPATIBILITY < 1.9
|
// <<< BACKWARD COMPATIBILITY < 1.9
|
||||||
}
|
}
|
||||||
else if ( provider == "gdal" && mDataSource.startsWith( "NETCDF:" ) )
|
else
|
||||||
|
{
|
||||||
|
bool handled = false;
|
||||||
|
|
||||||
|
if ( provider == "gdal" )
|
||||||
|
{
|
||||||
|
if ( mDataSource.startsWith( "NETCDF:" ) )
|
||||||
{
|
{
|
||||||
// NETCDF:filename:variable
|
// NETCDF:filename:variable
|
||||||
// filename can be quoted with " as it can contain colons
|
// filename can be quoted with " as it can contain colons
|
||||||
@ -303,9 +309,10 @@ bool QgsMapLayer::readLayerXML( const QDomElement& layerElement )
|
|||||||
if ( filename.startsWith( '"' ) && filename.endsWith( '"' ) )
|
if ( filename.startsWith( '"' ) && filename.endsWith( '"' ) )
|
||||||
filename = filename.mid( 1, filename.length() - 2 );
|
filename = filename.mid( 1, filename.length() - 2 );
|
||||||
mDataSource = "NETCDF:\"" + QgsProject::instance()->readPath( filename ) + "\":" + r.cap( 2 );
|
mDataSource = "NETCDF:\"" + QgsProject::instance()->readPath( filename ) + "\":" + r.cap( 2 );
|
||||||
|
handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( provider == "gdal" && mDataSource.startsWith( "HDF4_SDS:" ) )
|
else if ( mDataSource.startsWith( "HDF4_SDS:" ) )
|
||||||
{
|
{
|
||||||
// HDF4_SDS:subdataset_type:file_name:subdataset_index
|
// HDF4_SDS:subdataset_type:file_name:subdataset_index
|
||||||
// filename can be quoted with " as it can contain colons
|
// filename can be quoted with " as it can contain colons
|
||||||
@ -316,9 +323,10 @@ bool QgsMapLayer::readLayerXML( const QDomElement& layerElement )
|
|||||||
if ( filename.startsWith( '"' ) && filename.endsWith( '"' ) )
|
if ( filename.startsWith( '"' ) && filename.endsWith( '"' ) )
|
||||||
filename = filename.mid( 1, filename.length() - 2 );
|
filename = filename.mid( 1, filename.length() - 2 );
|
||||||
mDataSource = "HDF4_SDS:" + r.cap( 1 ) + ":\"" + QgsProject::instance()->readPath( filename ) + "\":" + r.cap( 3 );
|
mDataSource = "HDF4_SDS:" + r.cap( 1 ) + ":\"" + QgsProject::instance()->readPath( filename ) + "\":" + r.cap( 3 );
|
||||||
|
handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( provider == "gdal" && mDataSource.startsWith( "HDF5:" ) )
|
else if ( mDataSource.startsWith( "HDF5:" ) )
|
||||||
{
|
{
|
||||||
// HDF5:file_name:subdataset
|
// HDF5:file_name:subdataset
|
||||||
// filename can be quoted with " as it can contain colons
|
// filename can be quoted with " as it can contain colons
|
||||||
@ -329,9 +337,10 @@ bool QgsMapLayer::readLayerXML( const QDomElement& layerElement )
|
|||||||
if ( filename.startsWith( '"' ) && filename.endsWith( '"' ) )
|
if ( filename.startsWith( '"' ) && filename.endsWith( '"' ) )
|
||||||
filename = filename.mid( 1, filename.length() - 2 );
|
filename = filename.mid( 1, filename.length() - 2 );
|
||||||
mDataSource = "HDF5:\"" + QgsProject::instance()->readPath( filename ) + "\":" + r.cap( 2 );
|
mDataSource = "HDF5:\"" + QgsProject::instance()->readPath( filename ) + "\":" + r.cap( 2 );
|
||||||
|
handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( provider == "gdal" && mDataSource.contains( QRegExp( "^(NITF_IM|RADARSAT_2_CALIB):" ) ) )
|
else if ( mDataSource.contains( QRegExp( "^(NITF_IM|RADARSAT_2_CALIB):" ) ) )
|
||||||
{
|
{
|
||||||
// NITF_IM:0:filename
|
// NITF_IM:0:filename
|
||||||
// RADARSAT_2_CALIB:?:filename
|
// RADARSAT_2_CALIB:?:filename
|
||||||
@ -339,10 +348,12 @@ bool QgsMapLayer::readLayerXML( const QDomElement& layerElement )
|
|||||||
if ( r.exactMatch( mDataSource ) )
|
if ( r.exactMatch( mDataSource ) )
|
||||||
{
|
{
|
||||||
mDataSource = r.cap( 1 ) + ":" + r.cap( 2 ) + ":" + QgsProject::instance()->readPath( r.cap( 3 ) );
|
mDataSource = r.cap( 1 ) + ":" + r.cap( 2 ) + ":" + QgsProject::instance()->readPath( r.cap( 3 ) );
|
||||||
|
handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
|
||||||
|
if ( !handled )
|
||||||
mDataSource = QgsProject::instance()->readPath( mDataSource );
|
mDataSource = QgsProject::instance()->readPath( mDataSource );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -538,41 +549,73 @@ bool QgsMapLayer::writeLayerXML( QDomElement& layerElement, QDomDocument& docume
|
|||||||
urlDest.setQueryItems( urlSource.queryItems() );
|
urlDest.setQueryItems( urlSource.queryItems() );
|
||||||
src = QString::fromAscii( urlDest.toEncoded() );
|
src = QString::fromAscii( urlDest.toEncoded() );
|
||||||
}
|
}
|
||||||
else if ( !vlayer )
|
else
|
||||||
|
{
|
||||||
|
bool handled = false;
|
||||||
|
|
||||||
|
if ( !vlayer )
|
||||||
{
|
{
|
||||||
QgsRasterLayer *rlayer = qobject_cast<QgsRasterLayer *>( this );
|
QgsRasterLayer *rlayer = qobject_cast<QgsRasterLayer *>( this );
|
||||||
// Update path for subdataset
|
// Update path for subdataset
|
||||||
if ( rlayer && rlayer->providerType() == "gdal" )
|
if ( rlayer && rlayer->providerType() == "gdal" )
|
||||||
{
|
{
|
||||||
QStringList theURIParts = src.split( ":" );
|
if ( src.startsWith( "NETCDF:" ) )
|
||||||
if ( theURIParts[0] == "NETCDF" )
|
|
||||||
{
|
{
|
||||||
src = theURIParts[1];
|
// NETCDF:filename:variable
|
||||||
src.replace( "\"", "" );
|
// filename can be quoted with " as it can contain colons
|
||||||
src = QgsProject::instance()->writePath( src, relativeBasePath );
|
QRegExp r( "NETCDF:(.+):([^:]+)" );
|
||||||
theURIParts[1] = "\"" + src + "\"";
|
if ( r.exactMatch( src ) )
|
||||||
}
|
|
||||||
else if ( theURIParts[0] == "HDF4_SDS" )
|
|
||||||
{
|
{
|
||||||
theURIParts[2] = QgsProject::instance()->writePath( theURIParts[2], relativeBasePath );
|
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 ( theURIParts[0] == "HDF5" )
|
}
|
||||||
|
else if ( src.startsWith( "HDF4_SDS:" ) )
|
||||||
{
|
{
|
||||||
theURIParts[1] = QgsProject::instance()->writePath( theURIParts[1], relativeBasePath );
|
// HDF4_SDS:subdataset_type:file_name:subdataset_index
|
||||||
}
|
// filename can be quoted with " as it can contain colons
|
||||||
else if ( theURIParts[0] == "NITF_IM" )
|
QRegExp r( "HDF4_SDS:([^:]+):(.+):([^:]+)" );
|
||||||
|
if ( r.exactMatch( src ) )
|
||||||
{
|
{
|
||||||
theURIParts[2] = QgsProject::instance()->writePath( theURIParts[2], relativeBasePath );
|
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 ( theURIParts[0] == "RADARSAT_2_CALIB" )
|
}
|
||||||
|
else if ( src.startsWith( "HDF5:" ) )
|
||||||
{
|
{
|
||||||
theURIParts[2] = QgsProject::instance()->writePath( theURIParts[2], relativeBasePath );
|
// HDF5:file_name:subdataset
|
||||||
}
|
// filename can be quoted with " as it can contain colons
|
||||||
src = theURIParts.join( ":" );
|
QRegExp r( "HDF5:(.+):([^:]+)" );
|
||||||
}
|
if ( r.exactMatch( src ) )
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
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 );
|
src = QgsProject::instance()->writePath( src, relativeBasePath );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user