1

I have a geotiff file that is single band but contains multiple subdatasets. I use gdal with numpy to open a specific subdataset and mask some of its values.

Example:

$ gdalinfo sample.tif
...
Subdatasets:
SUBDATASET_1_NAME=GTIFF_DIR:1:sample.tif
SUBDATASET_1_DESC=...
SUBDATASET_2_NAME=GTIFF_DIR:2:sample.tif
SUBDATASET_2_DESC=...
# pseudocode
sds = gdal.Open('GTIFF_DIR:2:sample.tif')
sds_mask = apply mask to sds

I want to put sds_mask back into the original geotiff or a copy of it. Is this possible with gdal?

I tried writing out all the subdatasets, modifying one of the subdatasets, and then merging them back together with gdal_translate and gdal_merge.py with the -separate option but it does not create a geotiff with subdatasets.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jul 26, 2013 at 20:55

1 Answer 1

1

GDAL can't do this to my knowledge, although LibTIFF (http://www.simplesystems.org/libtiff/) has a tool called "tiffcp" that can do this:

To create a file out.tif that has two subdatasets a.tif and b.tif:

tiffcp a.tif b.tif out.tif

If the TIF will be larger than 4GB, you'll have to use the "-8" option

answered Dec 9, 2016 at 23:40

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.