I've been playing around with C++ and the API for GDAL to create some functions that I have done using Python. One of them was to create a virtual raster based on a list of files found in certain directory. I accomplished the later using the boost library. And when it comes the turn to write the virtual raster, I find that the vrt generated only contains one band. I checked some questions regarding this problems, and the most close to my issue is found in the following link:
https://gis.stackexchange.com/questions/269976/c-gdal-api-add-more-than-one-rasters-to-vrt
However when compiling my program using
g++ -o stack_raster.exe stack_raster.cpp -lboost_system -lboost_filesystem -lgdal
I get the following message:
stack_raster.cpp:35:99: error: 'YES' was not declared in this scope ver->CreateCopy("media/B02_stack.vrt", poSrcDS,RALSE,APPEND_SUBDATASET=YES,NULL,NULL,NULL);
Before I was having no issues during the compilation by replacing APPEND_SUBDATASET=YES,NULL,NULL,NULL)
, for NULL
. The resulted Virtual raster generated only contains one band, as expected. Could someone gives me a hint about my problem?
This is my code:
#include <iostream>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include "gdal/gdal.h"
#include "gdal/cpl_conv.h" /* for CPLMalloc() */
#include "gdal/vrtdataset.h"
#include <iostream>
#include <string>
#include "gdal/cpl_string.h"
#include <stdbool.h>
using namespace std;
using namespace boost::filesystem;
int main()
{
GDALAllRegister();
path p("/home/roger/Documents/09_Stack_Raster/media");
GDALDriver *poDriver = (GDALDriver*) GDALGetDriverByName( "VRT" );
GDALDataset *poSrcDS, *poVRTDS;
string bdir = "media/";
for (auto i = directory_iterator(p); i != directory_iterator(); i++)
{
string filename = i -> path().filename().string();
cout << filename << endl;
if (!is_directory(i->path()) && boost::ends_with(filename, ".tif"))
{
cout << i->path().filename().string() << endl;
std::string str_path = "media/" + i->path().filename().string();
poSrcDS = (GDALDataset *) GDALOpenShared(str_path.c_str(), GA_ReadOnly);
poVRTDS = poDriver->CreateCopy("media/B02_stack.vrt", poSrcDS,FALSE,APPEND_SUBDATASET=YES,NULL,NULL);
GDALClose((GDALDatasetH) poSrcDS);
}
else
continue;
}
GDALClose((GDALDatasetH) poVRTDS);
}