<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! <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">" <SourceFilename>utm.tif</SourceFilename><font style="" color="#ff0000"><u>1</u></font><SourceBand>1</SourceBand>"</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> <br>With best regards.<br>~Belaid...<br>> From: even.rouault@mines-paris.org<br>> To: gdal-dev@lists.osgeo.org<br>> Subject: Re: [gdal-dev] moving averaging filter in GDAL.<br>> Date: Thu, 2 Jul 2009 20:20:09 +0200<br>> CC: belaid_moa@hotmail.com<br>> <br>> Belaid Moa,<br>> <br>> Good point! Yes it should work as your code is directly derived from the VRT <br>> tutorial. I discovered that in fact support for SetMetadataItem( "source_0", <br>> szFilterSourceXML, "vrt_sources" ) was missing in the VRT driver. I've fixed <br>> that as ticket #3052.<br>> <br>> In the meantime you've an easy workaround by using SetMetadata() instead of <br>> SetMetadataItem(). Here's the modified code snippet :<br>> <br>> /**<br>> * Apply an averaging filter to a GDALDataset<br>> * sFileName: source file name<br>> * dstFileName: destination file name<br>> * size: size of the filter (kernal)<br>> * coefficients: the coefficients of the filter.<br>> **/<br>> int average(char* sFileName, char* dstFileName, int size, const char* <br>> coefficients) {<br>> GDALDriver *poDriver = (GDALDriver *) GDALGetDriverByName( "VRT" );<br>> if (poDriver == NULL) {<br>> cout <<"VRT Driver not found!"<<endl;<br>> return -1;<br>> }<br>> GDALDataset *poVRTDS, *poSrcDS;<br>> poSrcDS = (GDALDataset *) GDALOpen( sFileName, GA_ReadOnly);<br>> poVRTDS = poDriver->CreateCopy( "", poSrcDS, FALSE, NULL, NULL, NULL );<br>> int nBand;<br>> for( nBand = 1; nBand <= poVRTDS->GetRasterCount(); nBand++ ) {<br>> GDALRasterBand *poBand = poVRTDS->GetRasterBand( nBand );<br>> char szFilterSourceXML[10000];<br>> /* note the addition of source_0= */<br>> sprintf( szFilterSourceXML,<br>> "source_0=<KernelFilteredSource>" <br>> " <SourceFilename>%s</SourceFilename><SourceBand>%d</SourceBand>"<br>> " <Kernel>"<br>> " <Size>%d</Size>"<br>> " <Coefs>%s</Coefs>"<br>> " </Kernel>"<br>> "</KernelFilteredSource>",<br>> sFileName,nBand,size,coefficients);<br>> cout << szFilterSourceXML <<endl;<br>> char* papszMetadata[2] = { (char*)szFilterSourceXML, NULL };<br>> poBand->SetMetadata( papszMetadata, "vrt_sources" );<br>> //poBand->FlushCache();<br>> }<br>> GDALDriver *poTIFFDriver = (GDALDriver *) GDALGetDriverByName( "GTiff" );<br>> if (poTIFFDriver == NULL) {<br>> cout <<"GTIFF Driver not found!"<<endl;<br>> return -1;<br>> }<br>> GDALDataset *poTiffDS;<br>> poTiffDS = poTIFFDriver->CreateCopy( dstFileName, poVRTDS, FALSE, NULL, <br>> NULL, NULL );<br>> poVRTDS->GetRasterBand( 1 )->FlushCache();<br>> <br>> GDALClose(poSrcDS);<br>> GDALClose(poTiffDS);<br>> GDALClose(poVRTDS);<br>> return 1;<br>> }<br>> <br>> Best regards,<br>> <br>> 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>