I am trying to write a program which is able to create a raster dataset
of any supported format. To do so, I first created a virtual dataset in
memory using the Create() function, then set the projection and add the
bands to the virtual dataset (no links to source datasets), and then
used the CreateCopy() function to create a non-virtual dataset from the
virtual dataset I just created. However, the CreateCopy() always
returned a NULL pointer. I also tried creating a temporary vrt file
using the Create() function before using CreateCopy(). Still, the
CreateCopy() returned a NULL pointer.<br>
Has anyone done this before or have any idea how to do this? Do I have
to link a source dataset to the virtual dataset before using
CreateCopy() to create a non-virtual dataset from the virtual dataset?
I just want to create an empty dataset in which all the pixels are set
to some initial value (for example, zero).<br>
<br>
I am using GDAL <a href="http://1.5.3./" target="_blank">1.5.3.</a> The following is the code I wrote:<br>
<br>
...<br>
GDALDriver *poDriver = (GDALDriver *) GDALGetDriverByName( "VRT" );<br>
GDALDataset *poVRTDS;<br>
poVRTDS = poVRTDriver->Create("", xSize, ySize,<br>
3, GDT_Byte,<br>
NULL);<br>
if(poVRTDS == NULL) {<br>
cerr << "Error: unable to create virtual GDAL dataset " \<br>
<< endl;<br>
return false;<br>
}<br>
<br>
if(poVRTDS->SetProjection(<div id=":wk" class="ArwC7c ckChnd">pProjRef) == CE_Failure ||<br>
poVRTDS->SetGeoTransform(adfGeoTransform) == CE_Failure) {<br>
cerr << "Error: unable to set projection for the virtual dataset" \<br>
<< endl;<br>
return false;<br>
}<br>
<br>
GDALDriver *poDriver = (GDALDriver *) GDALGetDriverByName( "Gtiff" );<br>
GDALDataset *poDesDS;<br>
poDesDS= poDriver->CreateCopy("myGTIFF.tif",<br>
poVRTDS,<br>
FALSE, NULL,<br>
NULL, NULL);<br>
if(poDesDS== NULL) {<br>
cerr << "Error: unable to create GDAL dataset" << endl;<br>
GDALClose(poVRTDS);<br>
return false;<br>
}<br>
GDALClose(poVRTDS);<br>
...</div><br clear="all"><br>-- <br><br>--== Qingfeng (Gene) Guan ==--<br>