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( &quot;VRT&quot; );<br>
GDALDataset *poVRTDS;<br>
poVRTDS = poVRTDriver-&gt;Create(&quot;&quot;, xSize, ySize,<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3, GDT_Byte,<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NULL);<br>
if(poVRTDS == NULL) {<br>
&nbsp;cerr &lt;&lt; &quot;Error: unable to create virtual GDAL dataset &quot; \<br>
 &nbsp; &nbsp; &nbsp;&lt;&lt; endl;<br>
&nbsp;return false;<br>
}<br>
<br>
if(poVRTDS-&gt;SetProjection(<div id=":wk" class="ArwC7c ckChnd">pProjRef) == CE_Failure ||<br>
 &nbsp;poVRTDS-&gt;SetGeoTransform(adfGeoTransform) == CE_Failure) {<br>
&nbsp;cerr &lt;&lt; &quot;Error: unable to set projection for the virtual dataset&quot; \<br>
 &nbsp; &nbsp; &nbsp;&lt;&lt; endl;<br>
&nbsp;return false;<br>
}<br>
<br>
GDALDriver *poDriver = (GDALDriver *) GDALGetDriverByName( &quot;Gtiff&quot; );<br>
GDALDataset *poDesDS;<br>
poDesDS= poDriver-&gt;CreateCopy(&quot;myGTIFF.tif&quot;,<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; poVRTDS,<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FALSE, NULL,<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NULL, NULL);<br>
&nbsp;if(poDesDS== NULL) {<br>
 &nbsp; cerr &lt;&lt; &quot;Error: unable to create GDAL dataset&quot; &lt;&lt; endl;<br>
 &nbsp; GDALClose(poVRTDS);<br>
 &nbsp; return false;<br>
&nbsp;}<br>
&nbsp;GDALClose(poVRTDS);<br>
...</div><br clear="all"><br>-- <br><br>--== Qingfeng (Gene) Guan ==--<br>