[gdal-dev] create mosaic using mask bands
Gregory, Matthew
matt.gregory at oregonstate.edu
Fri Apr 13 15:09:41 EDT 2012
Hi all,
I don't think I'm understanding correctly how to use masking bands. My goal is to create a mosaic between two adjacent rasters using mask bands on each raster to define the valid data. As a test, I have two single band GeoTiffs (north.tif and south.tif) that overlap by about 400 rows. I use the following Python script to create a small mask at the top center of the south image which creates the desired .msk file:
from osgeo import gdal, gdalconst
ds = gdal.Open('south.tif', gdalconst.GA_ReadOnly)
ds.CreateMaskBand(2)
rb = ds.GetRasterBand(1)
mask = rb.GetMaskBand()
data = mask.ReadAsArray()
data[:] = 255
data[0:500,2500:3000] = 0
mask.WriteArray(data)
ds = None
Then I try to merge the two images together:
gdal_merge.py -o merge.tif -of GTiff -createonly north.tif south.tif
gdalwarp north.tif south.tif merge.tif
I was expecting that the masked pixels from south.tif would be considered NODATA allowing the north.tif pixels to 'shine through' in that location. Instead the original pixel values from south.tif also show up in the mosaic.
thanks, matt
More information about the gdal-dev
mailing list