Skip to content

Commit 977d0ac

Browse files
committed
avoid including GDAL C++ api (fixes #17849)
1 parent 0d2e008 commit 977d0ac

File tree

6 files changed

+33
-28
lines changed

6 files changed

+33
-28
lines changed

src/analysis/raster/qgsalignraster.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "qgsalignraster.h"
1717

1818
#include <gdalwarper.h>
19-
#include <ogr_spatialref.h>
19+
#include <ogr_srs_api.h>
2020
#include <cpl_conv.h>
2121
#include <limits>
2222

src/core/qgsdataitem.cpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "qgsconfig.h"
4141

4242
// use GDAL VSI mechanism
43+
#define CPL_SUPRESS_CPLUSPLUS
4344
#include "cpl_vsi.h"
4445
#include "cpl_string.h"
4546

@@ -1301,7 +1302,7 @@ char **VSIReadDirRecursive1( const char *pszPath )
13011302
char **papszFiles1 = nullptr;
13021303
char **papszFiles2 = nullptr;
13031304
VSIStatBufL psStatBuf;
1304-
CPLString osTemp1, osTemp2;
1305+
QString temp1, temp2;
13051306
int i, j;
13061307
int nCount1, nCount2;
13071308

@@ -1315,41 +1316,35 @@ char **VSIReadDirRecursive1( const char *pszPath )
13151316
for ( i = 0; i < nCount1; i++ )
13161317
{
13171318
// build complete file name for stat
1318-
osTemp1.clear();
1319-
osTemp1.append( pszPath );
1320-
osTemp1.append( "/" );
1321-
osTemp1.append( papszFiles1[i] );
1319+
temp1 = QString( "%1/%2" ).arg( pszPath, papszFiles1[i] );
13221320

13231321
// if is file, add it
1324-
if ( VSIStatL( osTemp1.c_str(), &psStatBuf ) == 0 &&
1322+
if ( VSIStatL( temp1.toUtf8(), &psStatBuf ) == 0 &&
13251323
VSI_ISREG( psStatBuf.st_mode ) )
13261324
{
13271325
// oFiles.AddString( papszFiles1[i] );
13281326
papszOFiles = CSLAddString( papszOFiles, papszFiles1[i] );
13291327
}
1330-
else if ( VSIStatL( osTemp1.c_str(), &psStatBuf ) == 0 &&
1328+
else if ( VSIStatL( temp1.toUtf8(), &psStatBuf ) == 0 &&
13311329
VSI_ISDIR( psStatBuf.st_mode ) )
13321330
{
13331331
// add directory entry
1334-
osTemp2.clear();
1335-
osTemp2.append( papszFiles1[i] );
1336-
osTemp2.append( "/" );
1337-
// oFiles.AddString( osTemp2.c_str() );
1338-
papszOFiles = CSLAddString( papszOFiles, osTemp2.c_str() );
1332+
temp2 = QString( "%1/" ).arg( papszFiles1[i] );
1333+
1334+
// oFiles.AddString( temp2.toUtf8() );
1335+
papszOFiles = CSLAddString( papszOFiles, temp2.toUtf8() );
13391336

13401337
// recursively add files inside directory
1341-
papszFiles2 = VSIReadDirRecursive1( osTemp1.c_str() );
1338+
papszFiles2 = VSIReadDirRecursive1( temp1.toUtf8() );
13421339
if ( papszFiles2 )
13431340
{
13441341
nCount2 = CSLCount( papszFiles2 );
13451342
for ( j = 0; j < nCount2; j++ )
13461343
{
1347-
osTemp2.clear();
1348-
osTemp2.append( papszFiles1[i] );
1349-
osTemp2.append( "/" );
1350-
osTemp2.append( papszFiles2[j] );
1351-
// oFiles.AddString( osTemp2.c_str() );
1352-
papszOFiles = CSLAddString( papszOFiles, osTemp2.c_str() );
1344+
temp2 = QString( "%1/%2" ).arg( papszFiles1[i], papszFiles2[j] );
1345+
1346+
// oFiles.AddString( temp2.toUtf8() );
1347+
papszOFiles = CSLAddString( papszOFiles, temp2.toUtf8() );
13531348
}
13541349
CSLDestroy( papszFiles2 );
13551350
}

src/plugins/georeferencer/qgsimagewarper.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <cpl_string.h>
2121
#include <gdal.h>
2222
#include <gdalwarper.h>
23-
#include <ogr_spatialref.h>
23+
#include <ogr_srs_api.h>
2424

2525
#include <QFile>
2626
#include <QProgressDialog>
@@ -35,6 +35,10 @@
3535
#define TO8F(x) QFile::encodeName( x ).constData()
3636
#endif
3737

38+
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 2300
39+
#define OGRFree(x) CPLFree(x)
40+
#endif
41+
3842
bool QgsImageWarper::mWarpCanceled = false;
3943

4044
QgsImageWarper::QgsImageWarper( QWidget *theParent )
@@ -101,16 +105,23 @@ bool QgsImageWarper::createDestinationDataset( const QString &outputName, GDALDa
101105

102106
if ( crs.isValid() )
103107
{
104-
OGRSpatialReference oTargetSRS;
105-
oTargetSRS.importFromProj4( crs.toProj4().toLatin1().data() );
108+
OGRSpatialReferenceH oTargetSRS = OSRNewSpatialReference( nullptr );
109+
OGRErr err = OSRImportFromProj4( oTargetSRS, crs.toProj4().toUtf8() );
110+
if ( err != CE_None )
111+
{
112+
OSRDestroySpatialReference( oTargetSRS );
113+
return false;
114+
}
106115

107116
char *wkt = nullptr;
108-
OGRErr err = oTargetSRS.exportToWkt( &wkt );
117+
err = OSRExportToWkt( oTargetSRS, &wkt );
109118
if ( err != CE_None || GDALSetProjection( hDstDS, wkt ) != CE_None )
110119
{
120+
OSRDestroySpatialReference( oTargetSRS );
111121
OGRFree( wkt );
112122
return false;
113123
}
124+
OSRDestroySpatialReference( oTargetSRS );
114125
OGRFree( wkt );
115126
}
116127

src/plugins/oracle_raster/qgsselectgeoraster_ui.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020

2121
#include "gdal.h"
2222
#include "ogr_api.h"
23-
#include "ogrsf_frmts.h"
24-
#include <cpl_string.h>
23+
#include "cpl_string.h"
2524

2625
#include "qgsvectorlayer.h"
2726

src/providers/gdal/qgsgdalprovider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
#include <QDebug>
5050

5151
#include "gdalwarper.h"
52-
#include "ogr_spatialref.h"
52+
#include "ogr_srs_api.h"
5353
#include "cpl_conv.h"
5454
#include "cpl_string.h"
5555

src/providers/wcs/qgswcsprovider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#endif
4646

4747
#include "gdalwarper.h"
48-
#include "ogr_spatialref.h"
48+
#include "ogr_srs_api.h"
4949
#include "cpl_conv.h"
5050
#include "cpl_string.h"
5151

0 commit comments

Comments
 (0)