[gdal-dev] Masked VRT

Simon Wright Simon.Wright at jbarisk.com
Mon Feb 24 11:22:29 PST 2025


Dear subscribers

I'm exploring the use of a VRT to mosaic raster tiles while also applying a mask layer using separate mask tiles.
Below is a VRT I created to test this approach:

<VRTDataset rasterXSize="90" rasterYSize="90">
  <SRS dataAxisToSRSAxisMapping="2,1">GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]</SRS>
  <GeoTransform>  0.0000000000000000e+00,  1.0000000000000000e+00,  0.0000000000000000e+00,  9.0000000000000000e+01,  0.0000000000000000e+00, -1.0000000000000000e+00</GeoTransform>
  <VRTRasterBand dataType="Float32" band="1">
    <NoDataValue>-99</NoDataValue>
    <ColorInterp>Gray</ColorInterp>
    <SimpleSource resampling="nearest">
      <SourceFilename relativeToVRT="1">tile_00.tif</SourceFilename>
      <SourceBand>1</SourceBand>
      <SourceProperties RasterXSize="30" RasterYSize="30" DataType="Float32" BlockXSize="30" BlockYSize="30" />
      <SrcRect xOff="0" yOff="0" xSize="30" ySize="30" />
      <DstRect xOff="0" yOff="60" xSize="30" ySize="30" />
      <NODATA>-99</NODATA>
    </SimpleSource>
    <SimpleSource resampling="nearest">
      <SourceFilename relativeToVRT="1">tile_01.tif</SourceFilename>
      <SourceBand>1</SourceBand>
      <SourceProperties RasterXSize="30" RasterYSize="30" DataType="Float32" BlockXSize="30" BlockYSize="30" />
      <SrcRect xOff="0" yOff="0" xSize="30" ySize="30" />
      <DstRect xOff="0" yOff="30" xSize="30" ySize="30" />
      <NODATA>-99</NODATA>
    </SimpleSource>
    <SimpleSource resampling="nearest">
      <SourceFilename relativeToVRT="1">tile_02.tif</SourceFilename>
      <SourceBand>1</SourceBand>
      <SourceProperties RasterXSize="30" RasterYSize="30" DataType="Float32" BlockXSize="30" BlockYSize="30" />
      <SrcRect xOff="0" yOff="0" xSize="30" ySize="30" />
      <DstRect xOff="0" yOff="0" xSize="30" ySize="30" />
      <NODATA>-99</NODATA>
    </SimpleSource>
    <SimpleSource resampling="nearest">
      <SourceFilename relativeToVRT="1">tile_10.tif</SourceFilename>
      <SourceBand>1</SourceBand>
      <SourceProperties RasterXSize="30" RasterYSize="30" DataType="Float32" BlockXSize="30" BlockYSize="30" />
      <SrcRect xOff="0" yOff="0" xSize="30" ySize="30" />
      <DstRect xOff="30" yOff="60" xSize="30" ySize="30" />
      <NODATA>-99</NODATA>
    </SimpleSource>
    <SimpleSource resampling="nearest">
      <SourceFilename relativeToVRT="1">tile_11.tif</SourceFilename>
      <SourceBand>1</SourceBand>
      <SourceProperties RasterXSize="30" RasterYSize="30" DataType="Float32" BlockXSize="30" BlockYSize="30" />
      <SrcRect xOff="0" yOff="0" xSize="30" ySize="30" />
      <DstRect xOff="30" yOff="30" xSize="30" ySize="30" />
      <NODATA>-99</NODATA>
    </SimpleSource>
    <SimpleSource resampling="nearest">
      <SourceFilename relativeToVRT="1">tile_12.tif</SourceFilename>
      <SourceBand>1</SourceBand>
      <SourceProperties RasterXSize="30" RasterYSize="30" DataType="Float32" BlockXSize="30" BlockYSize="30" />
      <SrcRect xOff="0" yOff="0" xSize="30" ySize="30" />
      <DstRect xOff="30" yOff="0" xSize="30" ySize="30" />
      <NODATA>-99</NODATA>
    </SimpleSource>
    <SimpleSource resampling="nearest">
      <SourceFilename relativeToVRT="1">tile_20.tif</SourceFilename>
      <SourceBand>1</SourceBand>
      <SourceProperties RasterXSize="30" RasterYSize="30" DataType="Float32" BlockXSize="30" BlockYSize="30" />
      <SrcRect xOff="0" yOff="0" xSize="30" ySize="30" />
      <DstRect xOff="60" yOff="60" xSize="30" ySize="30" />
      <NODATA>-99</NODATA>
    </SimpleSource>
    <SimpleSource resampling="nearest">
      <SourceFilename relativeToVRT="1">tile_21.tif</SourceFilename>
      <SourceBand>1</SourceBand>
      <SourceProperties RasterXSize="30" RasterYSize="30" DataType="Float32" BlockXSize="30" BlockYSize="30" />
      <SrcRect xOff="0" yOff="0" xSize="30" ySize="30" />
      <DstRect xOff="60" yOff="30" xSize="30" ySize="30" />
      <NODATA>-99</NODATA>
    </SimpleSource>
    <SimpleSource resampling="nearest">
      <SourceFilename relativeToVRT="1">tile_22.tif</SourceFilename>
      <SourceBand>1</SourceBand>
      <SourceProperties RasterXSize="30" RasterYSize="30" DataType="Float32" BlockXSize="30" BlockYSize="30" />
      <SrcRect xOff="0" yOff="0" xSize="30" ySize="30" />
      <DstRect xOff="60" yOff="0" xSize="30" ySize="30" />
      <NODATA>-99</NODATA>
    </SimpleSource>
  </VRTRasterBand>
  <MaskBand>
    <VRTRasterBand dataType="Byte">
      <NoDataValue>0</NoDataValue>
      <SimpleSource>
        <SourceFilename relativeToVRT="1">mask_m11.tif</SourceFilename>
        <SourceBand>1</SourceBand>
        <SrcRect xOff="0" yOff="0" xSize="30" ySize="30" />
        <DstRect xOff="30" yOff="30" xSize="30" ySize="30" />
      </SimpleSource>
      <SimpleSource>
        <SourceFilename relativeToVRT="1">mask_m12.tif</SourceFilename>
        <SourceBand>1</SourceBand>
        <SrcRect xOff="0" yOff="0" xSize="30" ySize="30" />
        <DstRect xOff="30" yOff="0" xSize="30" ySize="30" />
      </SimpleSource>
      <SimpleSource>
        <SourceFilename relativeToVRT="1">mask_m21.tif</SourceFilename>
        <SourceBand>1</SourceBand>
        <SrcRect xOff="0" yOff="0" xSize="30" ySize="30" />
        <DstRect xOff="60" yOff="30" xSize="30" ySize="30" />
      </SimpleSource>
      <SimpleSource>
        <SourceFilename relativeToVRT="1">mask_m22.tif</SourceFilename>
        <SourceBand>1</SourceBand>
        <SrcRect xOff="0" yOff="0" xSize="30" ySize="30" />
        <DstRect xOff="60" yOff="0" xSize="30" ySize="30" />
      </SimpleSource>
    </VRTRasterBand>
  </MaskBand>
</VRTDataset>

This VRT consists of nine 30 × 30 pixel raster tiles arranged in a 3 × 3 grid, with a mask layer composed of four tiles.
When I display the VRT in QGIS, only those raster tiles that intersect the mask tiles are visible. Similarly, when querying the masked VRT using a Python script using a GDAL dataset, a GDAL band, and a NumPy masked array, I retrieve data only from tiles that overlap the mask tiles.
My question is: Do I need to provide mask tiles covering the entire extent of the raster mosaic, or is there an alternative approach that allows me to use mask tiles only where I want to mask specific areas (e.g., to reduce redundancy)?
I’d appreciate any guidance or advice.


Many thanks in advance of any guidance or advice any can provide, best wishes, Simon.





Simon Wright

GISMO Scrum Master and RML Head of Software



--



e: Simon.Wright at jbarisk.com
d:+44 (0)1756 587258
t: +44 (0)1756 799919
www.jbarisk.com
All JBA Risk Management's email messages contain confidential information and are intended only for the individual(s) named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail.
Please notify the sender immediately by email if you have received this email by mistake and delete this email from your system. 
JBA Risk Management Limited is registered in England, company number 07732946, 1 Broughton Park, Old Lane North, Broughton, Skipton, North Yorkshire, BD23 3FD, England.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20250224/fd912e50/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image525632.png
Type: image/png
Size: 7388 bytes
Desc: image525632.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20250224/fd912e50/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image461331.png
Type: image/png
Size: 5172 bytes
Desc: image461331.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20250224/fd912e50/attachment-0005.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image334330.png
Type: image/png
Size: 774 bytes
Desc: image334330.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20250224/fd912e50/attachment-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image433886.png
Type: image/png
Size: 797 bytes
Desc: image433886.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20250224/fd912e50/attachment-0007.png>


More information about the gdal-dev mailing list