Simon, Setting the NoData value of your mask band to 255 instead of 0 should cause pixels not covered by a mask tile to be considered valid.
Dan On Mon, Feb 24, 2025 at 2:37 PM Simon Wright via gdal-dev < gdal-dev@lists.osgeo.org> wrote: > 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.wri...@jbarisk.com > > d: > > +44 (0)1756 587258 > > t: > > +44 (0)1756 799919 <+44%20(0)1756%20799919> > > www.jbarisk.com > > <https://www.linkedin.com/company/jba-risk-management/> > > <https://www.youtube.com/channel/UC0iatom2jYbW96voW0rlpCw> > > > > > 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. > _______________________________________________ > gdal-dev mailing list > gdal-dev@lists.osgeo.org > https://lists.osgeo.org/mailman/listinfo/gdal-dev >
_______________________________________________ gdal-dev mailing list gdal-dev@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/gdal-dev