hello,<br><br>Im new with GDAL and i want add a gdal module to my application.this one should translate a file from a format to another like gdal_translat .<br>So i should read the sourcefile making it into a dataset.my problem is that in the copy() methode i should copy a data set to the copy one and chage many options like projection.<br>
i paste my module here and i wish that you can help me to copy the data set to the new one. i saw the tutorial and i dont see copy methode and if i should use band of dataset to copy a band to another one.<br><br><br><div class="codebox">
<div class="incqbox"><h4>Code:</h4><div class="scrollbox" style="height: 35em;"><pre>/*****************************************************************************<br> *    ogr2gui is an application used to convert and manipulate geospatial<br>
 *    data. It is based on the &quot;OGR Simple Feature Library&quot; from the <br> *    &quot;Geospatial Data Abstraction Library&quot; &lt;<a href="http://gdal.org">http://gdal.org</a>&gt;.<br> *<br> *    Copyright (c) 2009 Inventis &lt;mailto:<a href="mailto:developpement@inventis.ca">developpement@inventis.ca</a>&gt;<br>
 *<br> *    This program is free software: you can redistribute it and/or modify<br> *    it under the terms of the GNU General Public License as published by<br> *    the Free Software Foundation, either version 3 of the License, or<br>
 *    (at your option) any later version.<br> *<br> *    This program is distributed in the hope that it will be useful,<br> *    but WITHOUT ANY WARRANTY; without even the implied warranty of<br> *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>
 *    GNU General Public License for more details.<br> *<br> *    You should have received a copy of the GNU General Public License<br> *    along with this program.  If not, see &lt;<a href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>&gt;<br>
 *****************************************************************************/<br><br>/*!<br> *    \file Cvt.cpp<br> *    \brief Cvt<br> *    \author Mohamed Hedi Lassoued [ Inventis ]<br> *    \version 0.5<br> *    \date 13/01/09<br>
 */<br><br><br>#include &quot;../inc/Cvt.h&quot;<br><br>#include &quot;gdal_priv.h&quot;<br>#include &quot;cpl_string.h&quot;<br><br>Cvt::Cvt( void )<br>{<br>    GDALAllRegister() ;<br>}<br><br>Cvt::~Cvt( void )<br>{<br><br>
}<br><br>bool Cvt::OpenDataset( const char * pszSrcFilename, const char * pszDstFilename )<br>{<br>    //Open the source file<br><br> poSrcDS = (GDALDataset *) GDALOpen( pszSrcFilename, GA_ReadOnly );<br>        if( poSrcDS != NULL )<br>
        {<br>            //succès d&#39;ouverture du Dataset <br>        }<br>    else<br>    {<br>        error = &quot;unable to open Dataset&quot;;<br>        return false;<br><br>    }<br><br>    //Open the target file<br>
poDstDS = (GDALDataset *) GDALOpen( pszDstFilename, GA_Update );<br>        if( poDstDS != NULL )<br>        {<br>            //succès d&#39;ouverture du Dataset <br>        }<br>    else<br>    {<br>        error = &quot;unable to open Dataset&quot;;<br>
        return false;<br><br>    }<br>}<br>int Cvt::VerfCreat();<br>{<br>    const char *pszFormat = &quot;GTiff&quot;; // target Format<br>    <br>    char **papszMetadata;<br><br>    poDstDriver = GetGDALDriverManager()-&gt;GetDriverByName(pszFormat);<br>
<br>    if( poDstDriver == NULL )<br>       // exit( 1 );<br>    return 0;<br>    // Vérification de possibilité d&#39;utilisation CREAT ou CREATCOPY<br>    papszMetadata = poDstDriver-&gt;GetMetadata();<br>    if( CSLFetchBoolean( papszMetadata, GDAL_DCAP_CREATE, FALSE ) )<br>
        {<br>        printf( &quot;Driver %s supports Create() method.\n&quot;, pszFormat );<br>        return 1;<br>    }<br>    if( CSLFetchBoolean( papszMetadata, GDAL_DCAP_CREATECOPY, FALSE ) )<br>        {<br>        printf( &quot;Driver %s supports CreateCopy() method.\n&quot;, pszFormat );<br>
        return 2;<br>    }<br><br>}<br><br>// creat of dataset copy with the new Format<br>//need to complet the if .... creat directly ....<br>bool Cvt::ConvertDataset();<br>{<br>    if ( VerfCreat()==2 ) // using CreateCopy<br>
    {<br>        poDstDS = poDstDriver-&gt;CreateCopy( pszDstFilename, poSrcDS, FALSE, <br>                        NULL, NULL, NULL );<br>    <br>    }<br>    else if ( VerfCreat()==1 ) // using Creat<br>    {<br>            <br>
        poDstDS = poDstDriver-&gt;Create( pszDstFilename, poSrcDS-&gt;GetRasterXSize(), poSrcDS-&gt;GetRasterYSize(),  poSrcDS-&gt;GetRasterCount(), GDT_Byte, <br>                    papszOptions );<br>    <br>        //Modification  that we can do for the poDstDS (add a geotransfor, UTM,  SetWellKnownGeogCS....<br>
        <br>        poDstDS-&gt;SetGeoTransform( adfGeoTransform );<br><br>        oSRS.SetUTM( 11, TRUE );<br>        oSRS.SetWellKnownGeogCS( &quot;NAD27&quot; );<br>        oSRS.exportToWkt( &amp;pszSRS_WKT );<br>        poDstDS-&gt;SetProjection( pszSRS_WKT );<br>
        CPLFree( pszSRS_WKT );<br><br><br><br><br><br>        <br>        for( int i = 1; i&lt;=poDstDS-&gt;GetRasterCount() ; i++ )<br>        {    <br>            poBand = poSrcDS-&gt;GetRasterBand(i);<br><br>            //il faut ecrire dans le poDstDS  le poband lu, nrmalement il y a un setRasterBand<br>
<br>            GByte abyRaster[poSrcDS-&gt;GetRasterXSize()*poSrcDS-&gt;GetRasterYSize()];<br>            poBand-&gt;RasterIO( GF_Read, 0, 0, poSrcDS-&gt;GetRasterXSize(), poSrcDS-&gt;GetRasterYSize(), <br>                abyRaster, 512, 512, GDT_Byte, 0, 0 ); <br>
            poDstDS = poDriver-&gt;Create( pszDstFilename, 512, 512, 1, GDT_Byte, <br>                        papszOptions );<br>        }<br>    }<br>            /* Once we&#39;re done, close properly the dataset */<br><br>
    if( poDstDS != NULL )<br>        GDALClose( (GDALDatasetH) poDstDS );<br>        GDALClose( (GDALDatasetH) poSrcDS );<br><br><br><br><br>thx all<br><br>}</pre></div></div></div><br>