[gdal-dev] How to add an external mask as internal mask to a GeoTIFF?

Daniele Romagnoli daniele.romagnoli at geo-solutions.it
Tue Jul 19 05:51:07 PDT 2016

Hi List,
I have a 4 Bands (RGB-IR) GeoTIFF for which I also have an external
mask.tif which has been created starting from a mask.shp shapefile using
this command:

*gdal_rasterize -ot Byte -l mask -CO "TILED=YES" -CO "NBITS=1" -CO
16384 mask.shp mask.tif*

So that my mask.tif is 1 bit B/W GeoTIFF.
Now, I would like to add it as Internal Mask of the main GeoTIFF.
I have played a bit with GDAL translate and buildvrt and, due to
constraints on number of bands, I ended up with this commands:

*gdalbuildvrt -b 1 1.vrt origin.tif gdalbuildvrt -b 2 2.vrt
origin.tifgdalbuildvrt -b 3 3.vrt origin.tif *
*gdalbuildvrt -b 4 4.vrt origin.tif *
In order to separate the bands
*gdalbuildvrt -separate out.vrt 1.vrt 2.vrt 3.vrt 4.vrt mask.tif *

in order to re-aggregate them into a single raster, together with the mask.

And finally:

*gdal_translate -of GTIFF -CO "PHOTOMETRIC=RGB" -CO "ALPHA=NO" -CO
"TILED=YES" -CO "COMPRESS=DEFLATE" -b 1 -b 2 -b 3 -b 4 -mask 5 out.vrt

So that I copy the 4 bands from VRT and add the 5th band as mask.

I have 2 issues with that:
1) This solution is really not optimal. Wondering if there is a single
command to attach an external tif as a mask band of an existing raster
(provided it has same CRS, resolution, bbox, ecc)
2) What I get is that the mask has been set as an external file
Is there any config option or opening option to open the final.tif in
update mode so that the band mask can be added as internal geotiff mask?

Please, let me know what do you think about it.

GeoServer Professional Services from the experts! Visit
http://goo.gl/it488V for more information.

Ing. Daniele Romagnoli
Senior Software Engineer

GeoSolutions S.A.S.
Via di Montramito 3/A
55054  Massarosa (LU)
phone: +39 0584 962313
fax:      +39 0584 1660272




Le informazioni contenute in questo messaggio di posta elettronica e/o
nel/i file/s allegato/i sono da considerarsi strettamente riservate. Il
loro utilizzo è consentito esclusivamente al destinatario del messaggio,
per le finalità indicate nel messaggio stesso. Qualora riceviate questo
messaggio senza esserne il destinatario, Vi preghiamo cortesemente di
darcene notizia via e-mail e di procedere alla distruzione del messaggio
stesso, cancellandolo dal Vostro sistema. Conservare il messaggio stesso,
divulgarlo anche in parte, distribuirlo ad altri soggetti, copiarlo, od
utilizzarlo per finalità diverse, costituisce comportamento contrario ai
principi dettati dal D.Lgs. 196/2003.

The information in this message and/or attachments, is intended solely for
the attention and use of the named addressee(s) and may be confidential or
proprietary in nature or covered by the provisions of privacy act
(Legislative Decree June, 30 2003, no.196 - Italy's New Data Protection
Code).Any use not in accord with its purpose, any disclosure, reproduction,
copying, distribution, or either dissemination, either whole or partial, is
strictly forbidden except previous formal approval of the named
addressee(s). If you are not the intended recipient, please contact
immediately the sender by telephone, fax or e-mail and delete the
information in this message that has been received in error. The sender
does not give any warranty or accept liability as the content, accuracy or
completeness of sent messages and accepts no responsibility  for changes
made after they were sent or for other risks which arise as a result of
e-mail transmission, viruses, etc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20160719/45108d3c/attachment.html>

More information about the gdal-dev mailing list