After I managed to store SVG symbols in Geopackage BLOBs (Read (and write) SVG from Geopackage with QGIS) another idea was growing in my mind: Maybe we can store simple GDAL VRT sources in GPKG BLOBs or *.qgz files, to bind these datasources to a QGIS project?
Here's a minimal VRT which shows the city of Vienna clipped from a public WMTS (https://basemap.at):
<VRTDataset rasterXSize="293885" rasterYSize="227105" subClass="VRTWarpedDataset">
<SRS dataAxisToSRSAxisMapping="1,2">EPSG:3857</SRS>
<GeoTransform> 1.8013609905169420e+06, 1.4929107087160037e-01, 0.0000000000000000e+00, 6.1606686197213698e+06, 0.0000000000000000e+00, -1.4929107087160004e-01</GeoTransform>
<VRTRasterBand dataType="Byte" band="1" subClass="VRTWarpedRasterBand">
<ColorInterp>Red</ColorInterp>
</VRTRasterBand>
<VRTRasterBand dataType="Byte" band="2" subClass="VRTWarpedRasterBand">
<ColorInterp>Green</ColorInterp>
</VRTRasterBand>
<VRTRasterBand dataType="Byte" band="3" subClass="VRTWarpedRasterBand">
<ColorInterp>Blue</ColorInterp>
</VRTRasterBand>
<VRTRasterBand dataType="Byte" band="4" subClass="VRTWarpedRasterBand">
<ColorInterp>Alpha</ColorInterp>
</VRTRasterBand>
<BlockXSize>512</BlockXSize>
<BlockYSize>128</BlockYSize>
<GDALWarpOptions>
<SourceDataset relativeToVRT="0">WMTS:https://www.basemap.at/wmts/1.0.0/WMTSCapabilities.xml,layer=bmaporthofoto30cm</SourceDataset>
<Transformer>
<ApproxTransformer>
<MaxError>0.125</MaxError>
<BaseTransformer>
<GenImgProjTransformer>
<SrcGeoTransform>977649.895640023053,0.149291070871599985,0,6281289.98263385892,0,-0.149291070871599985</SrcGeoTransform>
<SrcInvGeoTransform>-6548616.00182950962,6.69832424780491387,0,42074116.9981704801,0,-6.69832424780491387</SrcInvGeoTransform>
<DstGeoTransform>1801360.99051694199,0.149291070871600373,0,6160668.61972136982,0,-0.14929107087160004</DstGeoTransform>
<DstInvGeoTransform>-12066100.0018294789,6.6983242478048961,0,41266155.9981704652,0,-6.6983242478049112</DstInvGeoTransform>
</GenImgProjTransformer>
</BaseTransformer>
</ApproxTransformer>
</Transformer>
<BandList>
<BandMapping src="1" dst="1" />
<BandMapping src="2" dst="2" />
<BandMapping src="3" dst="3" />
</BandList>
<SrcAlphaBand>4</SrcAlphaBand>
<DstAlphaBand>4</DstAlphaBand>
<Cutline>MULTIPOLYGON (((5501234.2650394 1052508.13225313,5501234.2650394 791668.70254492,5834964.1589386 791668.70254492,5834964.1589386 1052508.13225313,5501234.2650394 1052508.13225313)))</Cutline>
</GDALWarpOptions>
</VRTDataset>
We could store the VRT file in a QGIS *.QGZ project file and retrieve it via /VSIZIP/, but unfortunately it will be deleted after a project save. (Maybe the core devs could define a QGZ folder where we can store some custom data which won't get lost?)
Geopackage BLOBs are no option either, because I couldn't find a way to open a data stream (i.e. base64 encoded) as VRT data source. It's possible to retrieve data from BLOBs using Python and open it in QGIS from a temp file, but I would prefer a more direct solution.
GDAL has so many Virtual File System handlers, maybe we could use VSIMEM or VSISTDIN to read the data from a Geopackage BLOB.
Does anyone have a brilliant idea to solve this tricky task without using too much Python code?
(@Even Rouault ... something for you?)