Skip to content

Commit

Permalink
avoid including GDAL C++ api (fixes #17849)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jan 14, 2018
1 parent 0d2e008 commit 977d0ac
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/analysis/raster/qgsalignraster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "qgsalignraster.h"

#include <gdalwarper.h>
#include <ogr_spatialref.h>
#include <ogr_srs_api.h>
#include <cpl_conv.h>
#include <limits>

Expand Down
33 changes: 14 additions & 19 deletions src/core/qgsdataitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "qgsconfig.h"

// use GDAL VSI mechanism
#define CPL_SUPRESS_CPLUSPLUS
#include "cpl_vsi.h"
#include "cpl_string.h"

Expand Down Expand Up @@ -1301,7 +1302,7 @@ char **VSIReadDirRecursive1( const char *pszPath )
char **papszFiles1 = nullptr;
char **papszFiles2 = nullptr;
VSIStatBufL psStatBuf;
CPLString osTemp1, osTemp2;
QString temp1, temp2;
int i, j;
int nCount1, nCount2;

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

// if is file, add it
if ( VSIStatL( osTemp1.c_str(), &psStatBuf ) == 0 &&
if ( VSIStatL( temp1.toUtf8(), &psStatBuf ) == 0 &&
VSI_ISREG( psStatBuf.st_mode ) )
{
// oFiles.AddString( papszFiles1[i] );
papszOFiles = CSLAddString( papszOFiles, papszFiles1[i] );
}
else if ( VSIStatL( osTemp1.c_str(), &psStatBuf ) == 0 &&
else if ( VSIStatL( temp1.toUtf8(), &psStatBuf ) == 0 &&
VSI_ISDIR( psStatBuf.st_mode ) )
{
// add directory entry
osTemp2.clear();
osTemp2.append( papszFiles1[i] );
osTemp2.append( "/" );
// oFiles.AddString( osTemp2.c_str() );
papszOFiles = CSLAddString( papszOFiles, osTemp2.c_str() );
temp2 = QString( "%1/" ).arg( papszFiles1[i] );

// oFiles.AddString( temp2.toUtf8() );
papszOFiles = CSLAddString( papszOFiles, temp2.toUtf8() );

// recursively add files inside directory
papszFiles2 = VSIReadDirRecursive1( osTemp1.c_str() );
papszFiles2 = VSIReadDirRecursive1( temp1.toUtf8() );
if ( papszFiles2 )
{
nCount2 = CSLCount( papszFiles2 );
for ( j = 0; j < nCount2; j++ )
{
osTemp2.clear();
osTemp2.append( papszFiles1[i] );
osTemp2.append( "/" );
osTemp2.append( papszFiles2[j] );
// oFiles.AddString( osTemp2.c_str() );
papszOFiles = CSLAddString( papszOFiles, osTemp2.c_str() );
temp2 = QString( "%1/%2" ).arg( papszFiles1[i], papszFiles2[j] );

// oFiles.AddString( temp2.toUtf8() );
papszOFiles = CSLAddString( papszOFiles, temp2.toUtf8() );
}
CSLDestroy( papszFiles2 );
}
Expand Down
19 changes: 15 additions & 4 deletions src/plugins/georeferencer/qgsimagewarper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <cpl_string.h>
#include <gdal.h>
#include <gdalwarper.h>
#include <ogr_spatialref.h>
#include <ogr_srs_api.h>

#include <QFile>
#include <QProgressDialog>
Expand All @@ -35,6 +35,10 @@
#define TO8F(x) QFile::encodeName( x ).constData()
#endif

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 2300
#define OGRFree(x) CPLFree(x)
#endif

bool QgsImageWarper::mWarpCanceled = false;

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

if ( crs.isValid() )
{
OGRSpatialReference oTargetSRS;
oTargetSRS.importFromProj4( crs.toProj4().toLatin1().data() );
OGRSpatialReferenceH oTargetSRS = OSRNewSpatialReference( nullptr );
OGRErr err = OSRImportFromProj4( oTargetSRS, crs.toProj4().toUtf8() );
if ( err != CE_None )
{
OSRDestroySpatialReference( oTargetSRS );
return false;
}

char *wkt = nullptr;
OGRErr err = oTargetSRS.exportToWkt( &wkt );
err = OSRExportToWkt( oTargetSRS, &wkt );
if ( err != CE_None || GDALSetProjection( hDstDS, wkt ) != CE_None )
{
OSRDestroySpatialReference( oTargetSRS );
OGRFree( wkt );
return false;
}
OSRDestroySpatialReference( oTargetSRS );
OGRFree( wkt );
}

Expand Down
3 changes: 1 addition & 2 deletions src/plugins/oracle_raster/qgsselectgeoraster_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

#include "gdal.h"
#include "ogr_api.h"
#include "ogrsf_frmts.h"
#include <cpl_string.h>
#include "cpl_string.h"

#include "qgsvectorlayer.h"

Expand Down
2 changes: 1 addition & 1 deletion src/providers/gdal/qgsgdalprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#include <QDebug>

#include "gdalwarper.h"
#include "ogr_spatialref.h"
#include "ogr_srs_api.h"
#include "cpl_conv.h"
#include "cpl_string.h"

Expand Down
2 changes: 1 addition & 1 deletion src/providers/wcs/qgswcsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#endif

#include "gdalwarper.h"
#include "ogr_spatialref.h"
#include "ogr_srs_api.h"
#include "cpl_conv.h"
#include "cpl_string.h"

Expand Down

0 comments on commit 977d0ac

Please sign in to comment.