Tuesday, 16 October 2018

C++ GDAL API: Add more than one rasters to VRT



I want to add more than one tiff file into a vrt file, Well Based on GDAL documentations it is possible to create a vrt using this code


GDALDriver *poDriver = (GDALDriver *) GDALGetDriverByName( "VRT" );
GDALDataset *poSrcDS, *poVRTDS;
poSrcDS = (GDALDataset *) GDALOpenShared( "utm.tif", GA_ReadOnly );
poVRTDS = poDriver->CreateCopy( "wrk.vrt", poSrcDS, FALSE, NULL, NULL, NULL );
GDALClose((GDALDatasetH) poVRTDS);
GDALClose((GDALDatasetH) poSrcDS);

but it only adds utm.tif. what If I want to add another set of images into this vrt file? can I use poDriver->CreateCopy again and it appends the images into the source vrt?



Answer




I'm pretty sure that adding


poSrcDS = poDriver->CreateCopy( "wrk.vrt", poSrcDS, FALSE,
APPEND_SUBDATASET=YES, NULL, NULL );

before closing the datasets should add the second dataset to the VRT as well.


Hope this helps


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...