@@ -1646,6 +1646,32 @@ bool QgsRasterLayer::writeXml( QDomNode &layer_node,
1646
1646
return writeSymbology ( layer_node, document, errorMsg, context );
1647
1647
}
1648
1648
1649
+ // TODO: this should ideally go to gdal provider (together with most of encodedSource() + decodedSource())
1650
+ static bool _parseGpkgColons ( const QString &src, QString &filename, QString &tablename )
1651
+ {
1652
+ // GDAL accepts the following input format: GPKG:filename:table
1653
+ // (GDAL won't accept quoted filename)
1654
+
1655
+ QStringList lst = src.split ( ' :' );
1656
+ if ( lst.count () != 3 && lst.count () != 4 )
1657
+ return false ;
1658
+
1659
+ tablename = lst.last ();
1660
+ if ( lst.count () == 3 )
1661
+ {
1662
+ filename = lst[1 ];
1663
+ return true ;
1664
+ }
1665
+ else if ( lst.count () == 4 && lst[1 ].count () == 1 && ( lst[2 ][0 ] == ' /' || lst[2 ][0 ] == ' \\ ' ) )
1666
+ {
1667
+ // a bit of handling to make sure that filename C:\hello.gpkg is parsed correctly
1668
+ filename = lst[1 ] + " :" + lst[2 ];
1669
+ return true ;
1670
+ }
1671
+ return false ;
1672
+ }
1673
+
1674
+
1649
1675
QString QgsRasterLayer::encodedSource ( const QString &source, const QgsReadWriteContext &context ) const
1650
1676
{
1651
1677
QString src ( source );
@@ -1668,6 +1694,17 @@ QString QgsRasterLayer::encodedSource( const QString &source, const QgsReadWrite
1668
1694
handled = true ;
1669
1695
}
1670
1696
}
1697
+ else if ( src.startsWith ( QLatin1String ( " GPKG:" ) ) )
1698
+ {
1699
+ // GPKG:filename:table
1700
+ QString filename, tablename;
1701
+ if ( _parseGpkgColons ( src, filename, tablename ) )
1702
+ {
1703
+ filename = context.pathResolver ().writePath ( filename );
1704
+ src = QStringLiteral ( " GPKG:%1:%2" ).arg ( filename, tablename );
1705
+ handled = true ;
1706
+ }
1707
+ }
1671
1708
else if ( src.startsWith ( QLatin1String ( " HDF4_SDS:" ) ) )
1672
1709
{
1673
1710
// HDF4_SDS:subdataset_type:file_name:subdataset_index
@@ -1817,6 +1854,17 @@ QString QgsRasterLayer::decodedSource( const QString &source, const QString &pro
1817
1854
handled = true ;
1818
1855
}
1819
1856
}
1857
+ else if ( src.startsWith ( QLatin1String ( " GPKG:" ) ) )
1858
+ {
1859
+ // GPKG:filename:table
1860
+ QString filename, tablename;
1861
+ if ( _parseGpkgColons ( src, filename, tablename ) )
1862
+ {
1863
+ filename = context.pathResolver ().readPath ( filename );
1864
+ src = QStringLiteral ( " GPKG:%1:%2" ).arg ( filename, tablename );
1865
+ handled = true ;
1866
+ }
1867
+ }
1820
1868
else if ( src.startsWith ( QLatin1String ( " HDF4_SDS:" ) ) )
1821
1869
{
1822
1870
// HDF4_SDS:subdataset_type:file_name:subdataset_index
0 commit comments