Bonjour,
j'ai déclaré mon constructeur dans mon Ogr.h et je l'utilise dans le Ogr.cpp

mon probleme c'est que mon compilateur me génére une erreur un put bizzare
root@lassoued-laptop:/home/lassoued/ogr2gui-0.5# make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -Isrc -Iinc -I. -I. -o App.o src/App.cpp
In file included from src/../inc/../src/Frm.cpp:32,
from src/../inc/App.h:45,
from src/App.cpp:37:
src/../inc/../src/../src/Ogr.cpp:39: erreur: redefinition of «Ogr::Ogr()»
src/../src/../src/Ogr.cpp:39: erreur: «Ogr::Ogr()» previously defined here
src/../inc/../src/../src/Ogr.cpp:44: erreur: redefinition of «Ogr::~Ogr()»
src/../src/../src/Ogr.cpp:44: erreur: «Ogr::~Ogr()» previously defined here
src/../inc/../src/../src/Ogr.cpp:49: erreur: redefinition of «bool Ogr::OpenSource(std::string, std::string&, std::string&, std::string&)»
src/../src/../src/Ogr.cpp:49: erreur: «bool Ogr::OpenSource(std::string, std::string&, std::string&, std::string&)» previously defined here
src/../inc/../src/../src/Ogr.cpp:53: embrouillé par les erreurs précédentes, abandon
Preprocessed source stored into /tmp/ccouavR9.out file, please attach this to your bugreport.
make: *** [App.o] Erreur 1
voila mes classes :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
/*****************************************************************************
 *      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 Ogr.h
 *      \brief OGR C API
 *      \author Olivier Pilotte [ Inventis ]
 *      \version 0.5
 *      \date 13/01/09
 */
 
#ifndef OGR
#define OGR
 
/*!
 *      \class Ogr
 *      \brief OGR C API
 *      \author Olivier Pilotte
 */
class Ogr
{
	private :
 
		OGRSFDriverH formatDriver;
 
		OGRDataSourceH sourceData;
		OGRDataSourceH targetData;
 
		OGRLayerH squeryLayer;
		OGRLayerH sourceLayer;
		OGRLayerH targetLayer;
 
		OGRSpatialReferenceH sourceSRS;
		OGRSpatialReferenceH targetSRS;
 
		OGRFeatureDefnH sourceLayerDefn;
		OGRwkbGeometryType sourceLayerGeom;
 
		OGRGeometryH sourceGeom;
 
		string sourceName;
		string sourceLayerName;
		string targetName;
 
		string error;
 
		/*!
                 *      \fn bool Error( OGRErr e, string &s );
                 *      \brief OGR errors
                 *      \param e : OGR error
                 *      \param &s : error text
                 *      \returns true if error
                 */
		bool Error( OGRErr e, string &s );
 
	public :
 
		/*!
                 *      \fn Ogr( void );
                 *      \brief Constructor
                 */
		Ogr( void );
 
		/*!
                 *      \fn ~Ogr( void );
                 *      \brief Destructor
                 */
		~Ogr( void );
 
		/*!
                 *      \fn bool OpenSource( string filename, string &epsg = 0, string &query = 0, string &error = 0 );
                 *      \brief Opens source data
                 *      \param filename : source filename
                 *      \param &epsg : epsg code
                 *      \param &query : sql query
                 *      \param &error : error text
                 *      \returns true on success
                 */
		bool OpenSource( string filename, string &epsg, string &query, string &error );
 
		/*!
                 *      \fn bool CloseSource( void );
                 *      \brief Closes source data
                 *      \returns true on success
                 */
		bool CloseSource( void );
 
		/*!
                 *      \fn bool OpenDriver( string drivername, string error = 0 );
                 *      \brief Opens target driver
                 *      \param drivername : selected driver
                 *      \param error : error text
                 *      \returns true on success
                 */
		bool OpenDriver( string drivername, string error = 0 );
 
		/*!
                 *      \fn bool OpenTarget( string filename, int projection = 0, bool update = 0 );
                 *      \brief Opens target
                 *      \param filename : target filename
                 *      \param projection : epsg code
                 *      \param update : update mode
                 *      \returns true on success
                */
		bool OpenTarget( string filename, int projection = 0, bool update = 0 );
 
		/*!
                 *      \fn bool CloseTarget( void );
                 *      \brief Closes Target
                 *      \returns true on success
                 */
		bool CloseTarget( void );
 
		/*!
                 *      \fn bool Execute( string query = 0 );
                 *      \brief Execute conversion
                 *      \param query : source sql query
                 *      \returns true on success
                 */
		bool Execute( string query = 0 );
 
		/*!
                 *      \fn bool Prepare( int &nbFeat, string query );
                 *      \brief Prepare data for conversion
                 *      \param nbFeat : number of features
                 *      \param query : source sql query
                 *      \returns true on success
                 */
		bool Prepare( int &nbFeat, string query );
 
		/*!
                 *      \fn bool Process( void );
                 *      \brief Process a feature
                 *      \returns true on success
                 */
		bool Process( void );
};
 
#endif
[ code!]
 
 
 
classe Ogr.cpp
 
 
/*****************************************************************************
 *      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 Ogr.cpp
 *      \brief OGR C API
 *      \author Olivier Pilotte [ Inventis ]
 *      \version 0.5
 *      \date 13/01/09
 */
 
#include "ogr_api.h"
#include "ogr_srs_api.h"
 
#include <string>
#include <sys/stat.h>
using std::string;
 
#include "../inc/Ogr.h"
 
Ogr::Ogr( void )
{
	OGRRegisterAll();
}
 
Ogr::~Ogr( void )
{
 
}
 
bool Ogr::OpenSource( string filename, string &epsg, string &query, string &error )
{
	sourceSRS = NULL;
 
	sourceName = filename;
 
	sourceData = OGROpen( sourceName.c_str(), 0, NULL );
 
	if( sourceData != NULL )
	{
		sourceLayer = OGR_DS_GetLayer( sourceData, 0 );
 
		if( sourceLayer != NULL )
		{
			sourceLayerDefn = OGR_L_GetLayerDefn( sourceLayer );
 
			sourceLayerName = OGR_FD_GetName( sourceLayerDefn );
 
			sourceLayerGeom = OGR_FD_GetGeomType( sourceLayerDefn );
 
			sourceGeom = OGR_L_GetSpatialFilter( sourceLayer );
 
			sourceSRS = OGR_L_GetSpatialRef( sourceLayer );
 
			if( sourceSRS != NULL && ! Error( OSRAutoIdentifyEPSG( sourceSRS ), error ) )
			{
				epsg = OSRGetAttrValue( sourceSRS, "AUTHORITY", 1 );
			}
			else
			{
				error = "unable to open source spatial reference";
			}
 
			query = "SELECT * FROM " + sourceLayerName;
		}
		else
		{
			error = "unable to open source layer";
 
			return false;
		}
	}
	else
	{
		error = "unable to open source data";
 
		return false;
	}
 
	return true;
}
 
bool Ogr::CloseSource( void )
{
	if( sourceData != NULL )
	{
		OGR_DS_Destroy( sourceData );
	}
	else
	{
		return false;
	}
 
	return true;
}
 
 
bool Ogr::OpenDriver( string drivername, string error )
{
	formatDriver = OGRGetDriverByName( drivername.c_str() );
 
	if( formatDriver == NULL )
	{
		error = "unable to find driver";
 
		return false;
	}
 
	return true;
}
 
bool Ogr::OpenTarget( string filename, int projection, bool update )
{
	struct stat fileInfo;
 
	targetSRS = NULL;
 
	targetName = filename;
 
	if( projection > 0 )
	{
		targetSRS = OSRNewSpatialReference( NULL );
 
		if( Error( OSRImportFromEPSG( targetSRS, projection ), error ) )
		{
			error.insert( 0, "unable to create spatial reference : " );
		}
	}
 
	if( update )
	{
		if( stat( targetName.c_str(), &fileInfo ) == 0 )
		{
			targetData = OGR_Dr_Open( formatDriver, targetName.c_str(), 1 );
		}
		else
		{
			error = "file doesn't exist";
 
			return false;
		}
	}
	else
	{	
		if( stat( targetName.c_str(), &fileInfo ) == 0 )
		{
			if( remove( targetName.c_str() ) != 0 )
			{
				error = "unable to delete source data";
			}
		}
 
		targetData = OGR_Dr_CreateDataSource( formatDriver, targetName.c_str(), 0 );
	}
 
	if( targetData != NULL )
	{
		if( update )
		{
			targetLayer = OGR_DS_GetLayer( targetData, 0 );
		}
		else
		{
			if( targetSRS != NULL )
			{
				targetLayer = OGR_DS_CreateLayer( targetData, sourceLayerName.c_str(), targetSRS, sourceLayerGeom, NULL );
			}
			else
			{
				targetLayer = OGR_DS_CreateLayer( targetData, sourceLayerName.c_str(), sourceSRS, sourceLayerGeom, NULL );
			}
		}
	}
	else
	{
		error = "unable to create target data";
 
		return false;
	}
 
	return true;
}
 
bool Ogr::CloseTarget( void )
{
	if( targetData != NULL )
	{
		OGR_DS_Destroy( targetData );
	}
	else
	{
		return false;
	}
 
	return true;
}
 
 
bool Ogr::Execute( string query )
{
	int featuresCount = 0;
 
	if( Prepare( featuresCount, query ) )
	{
		while( Process() );
 
		CloseTarget();
 
		CloseSource();
	}
	else
	{
		return false;
	}
 
	return true;
}
 
 
bool Ogr::Prepare( int &featuresCount, string query )
{
	OGRFeatureDefnH featDefn = OGR_L_GetLayerDefn( sourceLayer );
 
	for( int i = 0; i < OGR_FD_GetFieldCount( sourceLayerDefn ); i ++ )
	{
		OGRFieldDefnH field = OGR_FD_GetFieldDefn( featDefn, i );
 
		if( Error( OGR_L_CreateField( targetLayer, field, 0 ), error ) )
		{
			return false;
		}
	}
 
	if( query.size() > 0 )
	{
		OGRLayerH squeryLayer = OGR_DS_ExecuteSQL( sourceData, query.c_str(), NULL, "" );
 
		if( squeryLayer != NULL )
		{
			sourceLayer = squeryLayer;
		}
	}
 
	OGR_L_ResetReading( sourceLayer );
 
	featuresCount = OGR_L_GetFeatureCount( sourceLayer, 1 );
 
	return true;
}
 
bool Ogr::Process( void )
{
	OGRFeatureH feature;
 
	if( ( ( feature = OGR_L_GetNextFeature( sourceLayer ) ) != NULL ) )
	{
		if( targetSRS )
		{
			Error( OGR_G_TransformTo( OGR_F_GetGeometryRef( feature ), targetSRS ), error );
		}
 
		Error( OGR_L_CreateFeature( targetLayer, feature ), error );
 
		OGR_F_Destroy( feature );
	}
	else
	{
		return false;
	}
 
	return true;
}
 
bool Ogr::Error( OGRErr code, string &type )
{
	switch( code )
	{
		case OGRERR_NONE :
		{
			return false;
		}
		break;
 
		case OGRERR_NOT_ENOUGH_DATA :
		{
			type = "not enough data";
		}
		break;
 
		case OGRERR_NOT_ENOUGH_MEMORY :
		{
			type = "not enough memory";
		}
		break;
 
		case OGRERR_UNSUPPORTED_GEOMETRY_TYPE :
		{
			type = "unsupported geometry type";
		}
		break;
 
		case OGRERR_UNSUPPORTED_OPERATION :
		{
			type = "unsupported operation";
		}
		break;
 
		case OGRERR_CORRUPT_DATA :
		{
			type = "corrupt data";
		}
		break;
 
		case OGRERR_FAILURE :
		{
			type = "failure";
		}
		break;
 
		case OGRERR_UNSUPPORTED_SRS :
		{
			type = "unsupported srs";
		}
		break;
 
		default :
		{
			type = "unknown";
		}
		break;
	}
 
	return true;
}