<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
</style>
</head>
<body class='hmmessage'>
Even, you really made my day today!!! Thanks a lot for spotting that out. I spent almost one day staring at my code in vain! &nbsp; <br>BTW, in the GDAL VRT tutorial (http://www.gdal.org/gdal_vrttut.html), I noticed that there is an extra character (1)<br>in the XML description of KernalFilterSource as in: <br><pre class="fragment"><span class="stringliteral">"  &lt;SourceFilename&gt;utm.tif&lt;/SourceFilename&gt;<font style="" color="#ff0000"><u>1</u></font>&lt;SourceBand&gt;1&lt;/SourceBand&gt;"</span><br><br>I think that character (i.e. 1) should not be there, otherwise the XML is not well-formed.<br><br>Again, thank you Even for your help.<br><br>With best regards.<br>Belaid Moa.<br></pre><br>&nbsp; <br>With best regards.<br>~Belaid...<br>&gt; From: even.rouault@mines-paris.org<br>&gt; To: gdal-dev@lists.osgeo.org<br>&gt; Subject: Re: [gdal-dev] moving averaging filter in GDAL.<br>&gt; Date: Thu, 2 Jul 2009 20:20:09 +0200<br>&gt; CC: belaid_moa@hotmail.com<br>&gt; <br>&gt; Belaid Moa,<br>&gt; <br>&gt; Good point! Yes it should work as your code is directly derived from the VRT <br>&gt; tutorial. I discovered that in fact support for SetMetadataItem( "source_0", <br>&gt; szFilterSourceXML, "vrt_sources" ) was missing in the VRT driver. I've fixed <br>&gt; that as ticket #3052.<br>&gt; <br>&gt; In the meantime you've an easy workaround by using SetMetadata() instead of <br>&gt; SetMetadataItem(). Here's the modified code snippet :<br>&gt; <br>&gt; /**<br>&gt; * Apply an averaging filter to a GDALDataset<br>&gt; * sFileName: source file name<br>&gt; * dstFileName: destination file name<br>&gt; * size: size of the filter (kernal)<br>&gt; * coefficients: the coefficients of the filter.<br>&gt; **/<br>&gt; int average(char* sFileName, char* dstFileName, int size, const char* <br>&gt; coefficients) {<br>&gt; &nbsp; GDALDriver *poDriver = (GDALDriver *) GDALGetDriverByName( "VRT" );<br>&gt; &nbsp; if (poDriver == &nbsp;NULL) {<br>&gt; &nbsp; &nbsp; &nbsp; cout &lt;&lt;"VRT Driver not found!"&lt;&lt;endl;<br>&gt; &nbsp; &nbsp; &nbsp; return -1;<br>&gt; &nbsp; }<br>&gt; &nbsp; GDALDataset *poVRTDS, *poSrcDS;<br>&gt; &nbsp; poSrcDS = (GDALDataset *) GDALOpen( sFileName, GA_ReadOnly);<br>&gt; &nbsp; poVRTDS = poDriver-&gt;CreateCopy( "", poSrcDS, FALSE, NULL, NULL, NULL );<br>&gt; &nbsp; int &nbsp; nBand;<br>&gt; &nbsp; for( nBand = 1; nBand &lt;= poVRTDS-&gt;GetRasterCount(); nBand++ ) {<br>&gt; &nbsp; &nbsp; &nbsp; GDALRasterBand *poBand = poVRTDS-&gt;GetRasterBand( nBand );<br>&gt; &nbsp; &nbsp; &nbsp; char szFilterSourceXML[10000];<br>&gt; /* note the addition of source_0= */<br>&gt; &nbsp; &nbsp; &nbsp; sprintf( szFilterSourceXML,<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; "source_0=&lt;KernelFilteredSource&gt;" <br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; " &nbsp;&lt;SourceFilename&gt;%s&lt;/SourceFilename&gt;&lt;SourceBand&gt;%d&lt;/SourceBand&gt;"<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; " &nbsp;&lt;Kernel&gt;"<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; " &nbsp; &nbsp;&lt;Size&gt;%d&lt;/Size&gt;"<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; " &nbsp; &nbsp;&lt;Coefs&gt;%s&lt;/Coefs&gt;"<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; " &nbsp;&lt;/Kernel&gt;"<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; "&lt;/KernelFilteredSource&gt;",<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; sFileName,nBand,size,coefficients);<br>&gt; &nbsp; &nbsp; &nbsp; cout &lt;&lt; szFilterSourceXML &lt;&lt;endl;<br>&gt; &nbsp; &nbsp; &nbsp; char* papszMetadata[2] = { (char*)szFilterSourceXML, NULL };<br>&gt;       poBand-&gt;SetMetadata( papszMetadata, "vrt_sources" );<br>&gt; &nbsp; &nbsp; &nbsp; //poBand-&gt;FlushCache();<br>&gt; &nbsp; }<br>&gt; &nbsp; GDALDriver *poTIFFDriver = (GDALDriver *) GDALGetDriverByName( "GTiff" );<br>&gt; &nbsp; &nbsp;if (poTIFFDriver == &nbsp;NULL) {<br>&gt; &nbsp; &nbsp; &nbsp; cout &lt;&lt;"GTIFF Driver not found!"&lt;&lt;endl;<br>&gt; &nbsp; &nbsp; &nbsp; return -1;<br>&gt; &nbsp; }<br>&gt; &nbsp; GDALDataset *poTiffDS;<br>&gt; &nbsp; poTiffDS = poTIFFDriver-&gt;CreateCopy( dstFileName, poVRTDS, FALSE, NULL, <br>&gt; NULL, NULL );<br>&gt; &nbsp; poVRTDS-&gt;GetRasterBand( 1 )-&gt;FlushCache();<br>&gt; <br>&gt; &nbsp; GDALClose(poSrcDS);<br>&gt; &nbsp; GDALClose(poTiffDS);<br>&gt; &nbsp; GDALClose(poVRTDS);<br>&gt; &nbsp; return 1;<br>&gt; }<br>&gt; <br>&gt; Best regards,<br>&gt; <br>&gt; Even<br><br /><hr />We are your photos. Share us now with  <a href='http://go.microsoft.com/?linkid=9666045' target='_new'>Windows Live Photos.</a></body>
</html>