<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
</style>
</head>
<body class='hmmessage'>
Hi,<br> As suggested by Frank and Even, I implemented a simple C++ version of gdalfilter.py (based on VRT driver) using the function below. Unfortunately, I keep getting the same data set as the source; no filtering is done at all! The destination file produced have the same content as the source file. Am I doing something wrong? Any help on this is very appreciated. I tried both gdal-1.4.1 and gdal-1.6.1 but no success.<br><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* 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> sprintf( szFilterSourceXML,<br> "<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> poBand->SetMetadataItem( "source_0", szFilterSourceXML, "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, NULL, NULL );<br> poVRTDS->GetRasterBand( 1 )->FlushCache();<br><br> GDALClose(poSrcDS);<br> GDALClose(poTiffDS);<br> GDALClose(poVRTDS);<br> return 1;<br>}<br>===========================================================================<br>With best regards.<br>Belaid Moa.<br><br><hr id="stopSpelling">From: belaid_moa@hotmail.com<br>To: gdal-dev@lists.osgeo.org<br>Subject: RE: [gdal-dev] moving filter averaging in GDAL.<br>Date: Fri, 19 Jun 2009 17:50:02 +0000<br><br>
<style>
.ExternalClass .EC_hmmessage P
{padding:0px;}
.ExternalClass body.EC_hmmessage
{font-size:10pt;font-family:Verdana;}
</style>
Thank you very much Even. I was just making sure I am not reinventing the wheel :).<br>I will then write the C++ version.<br><br>With best regards.<br>~Belaid...<br><br>> From: even.rouault@mines-paris.org<br>> To: gdal-dev@lists.osgeo.org<br>> Subject: Re: [gdal-dev] moving filter averaging in GDAL.<br>> Date: Fri, 19 Jun 2009 19:44:10 +0200<br>> CC: belaid_moa@hotmail.com<br>> <br>> It should be relatively straighforward to transpose from Python to C++, as <br>> Python API is mostly deduced from the original C++ one. Look at the <br>> documentation of the C++ API on gdal.org<br>> <br>> Le Friday 19 June 2009 19:27:40 Belaid MOA, vous avez écrit :<br>> > Thanks a lot Frank. Is there any C/C++ version for that? I am doing the<br>> > averaging filter from C++ code.<br>> ><br>> > With best regards.<br>> > Belaid Moa.<br>> ><br>> > > Date: Fri, 19 Jun 2009 13:23:33 -0400<br>> > > From: warmerdam@pobox.com<br>> > > To: belaid_moa@hotmail.com<br>> > > CC: gdal-dev@lists.osgeo.org<br>> > > Subject: Re: [gdal-dev] moving filter averaging in GDAL.<br>> > ><br>> > > Belaid MOA wrote:<br>> > > > Hi,<br>> > > > Does GDAL have functions for applying an averaging filter of window,<br>> > > > say 11x11, to an image? This is something that comes up all the time in<br>> > > > image analysis. So, I suppose GDAL has built-in functions for that.<br>> > > ><br>> > > > Any help on this is very appreciated.<br>> > ><br>> > > Belaid,<br>> > ><br>> > > There is support for filtering, including average filtering, with the<br>> > > gdalfilter.py command in gdal/swig/python/samples. It accomplished<br>> > > by creating a virtual file using the <KernelFilteredSource> directive -<br>> > > so ultimately the work is done by the VRT driver.<br>> > ><br>> > > Best regards,<br>> > > --<br>> > > ---------------------------------------+---------------------------------<br>> > >----- I set the clouds in motion - turn up | Frank Warmerdam,<br>> > > warmerdam@pobox.com light and sound - activate the windows |<br>> > > http://pobox.com/~warmerdam and watch the world go round - Rush |<br>> > > Geospatial Programmer for Rent<br>> ><br>> > _________________________________________________________________<br>> > We are your photos. Share us now with Windows Live Photos.<br>> > http://go.microsoft.com/?linkid=9666047<br>> <br>> <br><br><hr>Attention all humans. We are your photos. <a href="http://go.microsoft.com/?linkid=9666044">Free us.</a><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>