hello, 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 . 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. 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.
Code: /***************************************************************************** * ogr2gui is an application used to convert and manipulate geospatial * data. It is based on the "OGR Simple Feature Library" from the * "Geospatial Data Abstraction Library" <http://gdal.org>. * * Copyright (c) 2009 Inventis <mailto:[email protected]> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/> *****************************************************************************/ /*! * \file Cvt.cpp * \brief Cvt * \author Mohamed Hedi Lassoued [ Inventis ] * \version 0.5 * \date 13/01/09 */ #include "../inc/Cvt.h" #include "gdal_priv.h" #include "cpl_string.h" Cvt::Cvt( void ) { GDALAllRegister() ; } Cvt::~Cvt( void ) { } bool Cvt::OpenDataset( const char * pszSrcFilename, const char * pszDstFilename ) { //Open the source file poSrcDS = (GDALDataset *) GDALOpen( pszSrcFilename, GA_ReadOnly ); if( poSrcDS != NULL ) { //succès d'ouverture du Dataset } else { error = "unable to open Dataset"; return false; } //Open the target file poDstDS = (GDALDataset *) GDALOpen( pszDstFilename, GA_Update ); if( poDstDS != NULL ) { //succès d'ouverture du Dataset } else { error = "unable to open Dataset"; return false; } } int Cvt::VerfCreat(); { const char *pszFormat = "GTiff"; // target Format char **papszMetadata; poDstDriver = GetGDALDriverManager()->GetDriverByName(pszFormat); if( poDstDriver == NULL ) // exit( 1 ); return 0; // Vérification de possibilité d'utilisation CREAT ou CREATCOPY papszMetadata = poDstDriver->GetMetadata(); if( CSLFetchBoolean( papszMetadata, GDAL_DCAP_CREATE, FALSE ) ) { printf( "Driver %s supports Create() method.\n", pszFormat ); return 1; } if( CSLFetchBoolean( papszMetadata, GDAL_DCAP_CREATECOPY, FALSE ) ) { printf( "Driver %s supports CreateCopy() method.\n", pszFormat ); return 2; } } // creat of dataset copy with the new Format //need to complet the if .... creat directly .... bool Cvt::ConvertDataset(); { if ( VerfCreat()==2 ) // using CreateCopy { poDstDS = poDstDriver->CreateCopy( pszDstFilename, poSrcDS, FALSE, NULL, NULL, NULL ); } else if ( VerfCreat()==1 ) // using Creat { poDstDS = poDstDriver->Create( pszDstFilename, poSrcDS->GetRasterXSize(), poSrcDS->GetRasterYSize(), poSrcDS->GetRasterCount(), GDT_Byte, papszOptions ); //Modification that we can do for the poDstDS (add a geotransfor, UTM, SetWellKnownGeogCS.... poDstDS->SetGeoTransform( adfGeoTransform ); oSRS.SetUTM( 11, TRUE ); oSRS.SetWellKnownGeogCS( "NAD27" ); oSRS.exportToWkt( &pszSRS_WKT ); poDstDS->SetProjection( pszSRS_WKT ); CPLFree( pszSRS_WKT ); for( int i = 1; i<=poDstDS->GetRasterCount() ; i++ ) { poBand = poSrcDS->GetRasterBand(i); //il faut ecrire dans le poDstDS le poband lu, nrmalement il y a un setRasterBand GByte abyRaster[poSrcDS->GetRasterXSize()*poSrcDS->GetRasterYSize()]; poBand->RasterIO( GF_Read, 0, 0, poSrcDS->GetRasterXSize(), poSrcDS->GetRasterYSize(), abyRaster, 512, 512, GDT_Byte, 0, 0 ); poDstDS = poDriver->Create( pszDstFilename, 512, 512, 1, GDT_Byte, papszOptions ); } } /* Once we're done, close properly the dataset */ if( poDstDS != NULL ) GDALClose( (GDALDatasetH) poDstDS ); GDALClose( (GDALDatasetH) poSrcDS ); thx all }
_______________________________________________ gdal-dev mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/gdal-dev
