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 "OGR Simple Feature Library" from the <br> * "Geospatial Data Abstraction Library" <<a href="http://gdal.org">http://gdal.org</a>>.<br> *<br> * Copyright (c) 2009 Inventis <mailto:<a href="mailto:developpement@inventis.ca">developpement@inventis.ca</a>><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 <<a href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>><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 "../inc/Cvt.h"<br><br>#include "gdal_priv.h"<br>#include "cpl_string.h"<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'ouverture du Dataset <br> }<br> else<br> {<br> error = "unable to open Dataset";<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'ouverture du Dataset <br> }<br> else<br> {<br> error = "unable to open Dataset";<br>
return false;<br><br> }<br>}<br>int Cvt::VerfCreat();<br>{<br> const char *pszFormat = "GTiff"; // target Format<br> <br> char **papszMetadata;<br><br> poDstDriver = GetGDALDriverManager()->GetDriverByName(pszFormat);<br>
<br> if( poDstDriver == NULL )<br> // exit( 1 );<br> return 0;<br> // Vérification de possibilité d'utilisation CREAT ou CREATCOPY<br> papszMetadata = poDstDriver->GetMetadata();<br> if( CSLFetchBoolean( papszMetadata, GDAL_DCAP_CREATE, FALSE ) )<br>
{<br> printf( "Driver %s supports Create() method.\n", pszFormat );<br> return 1;<br> }<br> if( CSLFetchBoolean( papszMetadata, GDAL_DCAP_CREATECOPY, FALSE ) )<br> {<br> printf( "Driver %s supports CreateCopy() method.\n", 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->CreateCopy( pszDstFilename, poSrcDS, FALSE, <br> NULL, NULL, NULL );<br> <br> }<br> else if ( VerfCreat()==1 ) // using Creat<br> {<br> <br>
poDstDS = poDstDriver->Create( pszDstFilename, poSrcDS->GetRasterXSize(), poSrcDS->GetRasterYSize(), poSrcDS->GetRasterCount(), GDT_Byte, <br> papszOptions );<br> <br> //Modification that we can do for the poDstDS (add a geotransfor, UTM, SetWellKnownGeogCS....<br>
<br> poDstDS->SetGeoTransform( adfGeoTransform );<br><br> oSRS.SetUTM( 11, TRUE );<br> oSRS.SetWellKnownGeogCS( "NAD27" );<br> oSRS.exportToWkt( &pszSRS_WKT );<br> poDstDS->SetProjection( pszSRS_WKT );<br>
CPLFree( pszSRS_WKT );<br><br><br><br><br><br> <br> for( int i = 1; i<=poDstDS->GetRasterCount() ; i++ )<br> { <br> poBand = poSrcDS->GetRasterBand(i);<br><br> //il faut ecrire dans le poDstDS le poband lu, nrmalement il y a un setRasterBand<br>
<br> GByte abyRaster[poSrcDS->GetRasterXSize()*poSrcDS->GetRasterYSize()];<br> poBand->RasterIO( GF_Read, 0, 0, poSrcDS->GetRasterXSize(), poSrcDS->GetRasterYSize(), <br> abyRaster, 512, 512, GDT_Byte, 0, 0 ); <br>
poDstDS = poDriver->Create( pszDstFilename, 512, 512, 1, GDT_Byte, <br> papszOptions );<br> }<br> }<br> /* Once we'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>