[gdal-dev] Masking

Frank Warmerdam warmerdam at pobox.com
Mon Jul 28 13:26:29 EDT 2008


Patrick Cannon wrote:
> Hello,
> 
> Has anyone used the GDAL mask feature?
> 
> I would like to mark part of an image as transparent.  The area is defined 
> as a polygon.
> 
> I have been trying to find documentation or examples on how to use the mask 
> feature but, so far no luck.
> 
> Could someone please point me in the right direction?

Patrick,

According to the RFC:

   http://trac.osgeo.org/gdal/wiki/rfc15_nodatabitmask

You can call CreateMaskBand() on either a GDALRasterBand or a GDALDataset,
likely passing in the flag "0" for a per-band plain validity mask.

After calling CreateMaskBand() you would presumably call GetMaskBand()
on the target base band to fetch the newly created mask band.  Then just
write to it conventionally using RasterIO().

I use some caveats because it isn't often used in this fashion.  Mostly the
masking is currently used to expose mask information already embedded in
datasets.

Let me know if you run into problems.

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org



More information about the gdal-dev mailing list