banniere

Le portail francophone de la géomatique


Toujours pas inscrit ? Mot de passe oublié ?
Nom d'utilisateur    Mot de passe              Toujours pas inscrit ?   Mot de passe oublié ?

Annonce

GEODATA DAYS 2024

#1 Fri 07 August 2009 21:17

chochatown
Juste Inscrit !
Date d'inscription: 1 Aug 2009
Messages: 1

écrire des données du band dans un dataset

bonjour ,

je suis nouveau dans le domaine géomatique et le developpement GDAL. J'aimerai savoir comment pourrai-je lire les bans d'un dataset et les ecrire dansun autre dataset pour le but de convetion du format ( avec le driver )
voila le bout de mon code que j'ai commencé.

est- ce c'est comme ca que je doit me lancer ?
et maintenant je truve pas comment ecrire dans le dataset destination la band lu de l'autre dataset?

voila j'ai mis un commentaire dans le code ou je doit ajouter la reponse de ma deuxieme question.


merci

Hedi

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:developpement@inventis.ca>
 *
 *    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 );

}

Hors ligne

 

Pied de page des forums

Powered by FluxBB