Skip to content

Commit 21ad4ed

Browse files
authored
Merge pull request #3940 from nyalldawson/gdal2
Bump minimum GDAL version to 2.0, remove old version #ifdefs
2 parents 313ec55 + 4b8c5be commit 21ad4ed

44 files changed

Lines changed: 110 additions & 688 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎cmake/FindGDAL.cmake‎

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,9 @@ ELSE(WIN32)
6161
ENDIF (NOT GDAL_VERSION)
6262
STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\1" GDAL_VERSION_MAJOR "${GDAL_VERSION}")
6363
STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\2" GDAL_VERSION_MINOR "${GDAL_VERSION}")
64-
IF (GDAL_VERSION_MAJOR LESS 1 OR (GDAL_VERSION EQUAL 1 AND GDAL_VERSION_MINOR LESS 4))
65-
MESSAGE (FATAL_ERROR "GDAL version is too old (${GDAL_VERSION}). Use 1.4.0 or higher.")
66-
ENDIF (GDAL_VERSION_MAJOR LESS 1 OR (GDAL_VERSION EQUAL 1 AND GDAL_VERSION_MINOR LESS 4))
67-
68-
IF (GDAL_VERSION_MAJOR LESS 1 OR (GDAL_VERSION_MAJOR EQUAL 1 AND GDAL_VERSION_MINOR LESS 11))
69-
MESSAGE (WARNING "GDAL version is too old (${GDAL_VERSION}) to support GeoPackage. 1.11.0 or higher is recommended.")
70-
ENDIF (GDAL_VERSION_MAJOR LESS 1 OR (GDAL_VERSION_MAJOR EQUAL 1 AND GDAL_VERSION_MINOR LESS 11))
64+
IF (GDAL_VERSION_MAJOR LESS 2)
65+
MESSAGE (FATAL_ERROR "GDAL version is too old (${GDAL_VERSION}). Use 2.0 or higher.")
66+
ENDIF (GDAL_VERSION_MAJOR LESS 2)
7167

7268
ENDIF (GDAL_LIBRARY)
7369
SET (CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK_save} CACHE STRING "" FORCE)
@@ -105,14 +101,10 @@ ELSE(WIN32)
105101

106102
# check for gdal version
107103
# version 1.2.5 is known NOT to be supported (missing CPL_STDCALL macro)
108-
# According to INSTALL, 1.4.0+ is required
109-
IF (GDAL_VERSION_MAJOR LESS 1 OR (GDAL_VERSION_MAJOR EQUAL 1 AND GDAL_VERSION_MINOR LESS 4))
110-
MESSAGE (FATAL_ERROR "GDAL version is too old (${GDAL_VERSION}). Use 1.4.0 or higher.")
111-
ENDIF (GDAL_VERSION_MAJOR LESS 1 OR (GDAL_VERSION_MAJOR EQUAL 1 AND GDAL_VERSION_MINOR LESS 4))
112-
113-
IF (GDAL_VERSION_MAJOR LESS 1 OR (GDAL_VERSION_MAJOR EQUAL 1 AND GDAL_VERSION_MINOR LESS 11))
114-
MESSAGE (WARNING "GDAL version is too old (${GDAL_VERSION}) to support GeoPackage. 1.11.0 or higher is recommended.")
115-
ENDIF (GDAL_VERSION_MAJOR LESS 1 OR (GDAL_VERSION_MAJOR EQUAL 1 AND GDAL_VERSION_MINOR LESS 11))
104+
# According to INSTALL, 2.0+ is required
105+
IF (GDAL_VERSION_MAJOR LESS 2)
106+
MESSAGE (FATAL_ERROR "GDAL version is too old (${GDAL_VERSION}). Use 2.0 or higher.")
107+
ENDIF (GDAL_VERSION_MAJOR LESS 2)
116108

117109
# set INCLUDE_DIR to prefix+include
118110
EXEC_PROGRAM(${GDAL_CONFIG}

‎src/analysis/raster/qgskde.cpp‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@
2323
#define M_PI 3.14159265358979323846
2424
#endif
2525

26-
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
27-
#define TO8F(x) (x).toUtf8().constData()
28-
#else
29-
#define TO8F(x) QFile::encodeName( x ).constData()
30-
#endif
31-
3226
QgsKernelDensityEstimation::QgsKernelDensityEstimation( const QgsKernelDensityEstimation::Parameters& parameters, const QString& outputFile, const QString& outputFormat )
3327
: mInputLayer( parameters.vectorLayer )
3428
, mOutputFile( outputFile )
@@ -99,7 +93,7 @@ QgsKernelDensityEstimation::Result QgsKernelDensityEstimation::prepare()
9993
return FileCreationError;
10094

10195
// open the raster in GA_Update mode
102-
mDatasetH = GDALOpen( TO8F( mOutputFile ), GA_Update );
96+
mDatasetH = GDALOpen( mOutputFile.toUtf8().constData(), GA_Update );
10397
if ( !mDatasetH )
10498
return FileCreationError;
10599
mRasterBandH = GDALGetRasterBand( mDatasetH, 1 );

‎src/analysis/raster/qgsninecellfilter.cpp‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@
2121
#include <QProgressDialog>
2222
#include <QFile>
2323

24-
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
25-
#define TO8F(x) (x).toUtf8().constData()
26-
#else
27-
#define TO8F(x) QFile::encodeName( x ).constData()
28-
#endif
29-
3024
QgsNineCellFilter::QgsNineCellFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat )
3125
: mInputFile( inputFile )
3226
, mOutputFile( outputFile )
@@ -208,7 +202,7 @@ int QgsNineCellFilter::processRaster( QProgressDialog* p )
208202
if ( p && p->wasCanceled() )
209203
{
210204
//delete the dataset without closing (because it is faster)
211-
GDALDeleteDataset( outputDriver, TO8F( mOutputFile ) );
205+
GDALDeleteDataset( outputDriver, mOutputFile.toUtf8().constData() );
212206
return 7;
213207
}
214208
GDALClose( outputDataset );
@@ -218,7 +212,7 @@ int QgsNineCellFilter::processRaster( QProgressDialog* p )
218212

219213
GDALDatasetH QgsNineCellFilter::openInputFile( int& nCellsX, int& nCellsY )
220214
{
221-
GDALDatasetH inputDataset = GDALOpen( TO8F( mInputFile ), GA_ReadOnly );
215+
GDALDatasetH inputDataset = GDALOpen( mInputFile.toUtf8().constData(), GA_ReadOnly );
222216
if ( inputDataset )
223217
{
224218
nCellsX = GDALGetRasterXSize( inputDataset );
@@ -267,7 +261,7 @@ GDALDatasetH QgsNineCellFilter::openOutputFile( GDALDatasetH inputDataset, GDALD
267261

268262
//open output file
269263
char **papszOptions = nullptr;
270-
GDALDatasetH outputDataset = GDALCreate( outputDriver, TO8F( mOutputFile ), xSize, ySize, 1, GDT_Float32, papszOptions );
264+
GDALDatasetH outputDataset = GDALCreate( outputDriver, mOutputFile.toUtf8().constData(), xSize, ySize, 1, GDT_Float32, papszOptions );
271265
if ( !outputDataset )
272266
{
273267
return outputDataset;

‎src/analysis/raster/qgsrastercalculator.cpp‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@
2929
#include <cpl_string.h>
3030
#include <gdalwarper.h>
3131

32-
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
33-
#define TO8(x) (x).toUtf8().constData()
34-
#define TO8F(x) (x).toUtf8().constData()
35-
#else
36-
#define TO8(x) (x).toLocal8Bit().constData()
37-
#define TO8F(x) QFile::encodeName( x ).constData()
38-
#endif
39-
4032
QgsRasterCalculator::QgsRasterCalculator( const QString& formulaString, const QString& outputFile, const QString& outputFormat,
4133
const QgsRectangle& outputExtent, int nOutputColumns, int nOutputRows, const QVector<QgsRasterCalculatorEntry>& rasterEntries )
4234
: mFormulaString( formulaString )
@@ -180,7 +172,7 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
180172
if ( p && p->wasCanceled() )
181173
{
182174
//delete the dataset without closing (because it is faster)
183-
GDALDeleteDataset( outputDriver, TO8F( mOutputFile ) );
175+
GDALDeleteDataset( outputDriver, mOutputFile.toUtf8().constData() );
184176
return static_cast< int >( Cancelled );
185177
}
186178
GDALClose( outputDataset );
@@ -219,7 +211,7 @@ GDALDatasetH QgsRasterCalculator::openOutputFile( GDALDriverH outputDriver )
219211
{
220212
//open output file
221213
char **papszOptions = nullptr;
222-
GDALDatasetH outputDataset = GDALCreate( outputDriver, TO8F( mOutputFile ), mNumOutputColumns, mNumOutputRows, 1, GDT_Float32, papszOptions );
214+
GDALDatasetH outputDataset = GDALCreate( outputDriver, mOutputFile.toUtf8().constData(), mNumOutputColumns, mNumOutputRows, 1, GDT_Float32, papszOptions );
223215
if ( !outputDataset )
224216
{
225217
return outputDataset;

‎src/analysis/raster/qgsrelief.cpp‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@
2828
#include <QFile>
2929
#include <QTextStream>
3030

31-
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
32-
#define TO8F(x) (x).toUtf8().constData()
33-
#else
34-
#define TO8F(x) QFile::encodeName( x ).constData()
35-
#endif
36-
3731
QgsRelief::QgsRelief( const QString& inputFile, const QString& outputFile, const QString& outputFormat )
3832
: mInputFile( inputFile )
3933
, mOutputFile( outputFile )
@@ -292,7 +286,7 @@ int QgsRelief::processRaster( QProgressDialog* p )
292286
if ( p && p->wasCanceled() )
293287
{
294288
//delete the dataset without closing (because it is faster)
295-
GDALDeleteDataset( outputDriver, TO8F( mOutputFile ) );
289+
GDALDeleteDataset( outputDriver, mOutputFile.toUtf8().constData() );
296290
return 7;
297291
}
298292
GDALClose( outputDataset );
@@ -415,7 +409,7 @@ bool QgsRelief::setElevationColor( double elevation, int* red, int* green, int*
415409
//duplicated from QgsNineCellFilter. Todo: make common base class
416410
GDALDatasetH QgsRelief::openInputFile( int& nCellsX, int& nCellsY )
417411
{
418-
GDALDatasetH inputDataset = GDALOpen( TO8F( mInputFile ), GA_ReadOnly );
412+
GDALDatasetH inputDataset = GDALOpen( mInputFile.toUtf8().constData(), GA_ReadOnly );
419413
if ( inputDataset )
420414
{
421415
nCellsX = GDALGetRasterXSize( inputDataset );
@@ -469,7 +463,7 @@ GDALDatasetH QgsRelief::openOutputFile( GDALDatasetH inputDataset, GDALDriverH o
469463
papszOptions = CSLSetNameValue( papszOptions, "COMPRESS", "PACKBITS" );
470464

471465
//create three band raster (reg, green, blue)
472-
GDALDatasetH outputDataset = GDALCreate( outputDriver, TO8F( mOutputFile ), xSize, ySize, 3, GDT_Byte, papszOptions );
466+
GDALDatasetH outputDataset = GDALCreate( outputDriver, mOutputFile.toUtf8().constData(), xSize, ySize, 3, GDT_Byte, papszOptions );
473467
if ( !outputDataset )
474468
{
475469
return outputDataset;

‎src/analysis/vector/qgszonalstatistics.cpp‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@
2828
#include <QProgressDialog>
2929
#include <QFile>
3030

31-
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
32-
#define TO8F(x) (x).toUtf8().constData()
33-
#else
34-
#define TO8F(x) QFile::encodeName( x ).constData()
35-
#endif
36-
3731
QgsZonalStatistics::QgsZonalStatistics( QgsVectorLayer* polygonLayer, const QString& rasterFile, const QString& attributePrefix, int rasterBand, Statistics stats )
3832
: mRasterFilePath( rasterFile )
3933
, mRasterBand( rasterBand )
@@ -69,7 +63,7 @@ int QgsZonalStatistics::calculateStatistics( QProgressDialog* p )
6963

7064
//open the raster layer and the raster band
7165
GDALAllRegister();
72-
GDALDatasetH inputDataset = GDALOpen( TO8F( mRasterFilePath ), GA_ReadOnly );
66+
GDALDatasetH inputDataset = GDALOpen( mRasterFilePath.toUtf8().constData(), GA_ReadOnly );
7367
if ( !inputDataset )
7468
{
7569
return 3;

‎src/app/dwg/qgsdwgimportdialog.cpp‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ QgsDwgImportDialog::QgsDwgImportDialog( QWidget *parent, Qt::WindowFlags f )
6969
cbMergeLayers->setChecked( s.value( "/DwgImport/lastMergeLayers", false ).toBool() );
7070
cbUseCurves->setChecked( s.value( "/DwgImport/lastUseCurves", true ).toBool() );
7171

72-
#if !defined(GDAL_COMPUTE_VERSION) || GDAL_VERSION_NUM < GDAL_COMPUTE_VERSION(2,0,0)
73-
cbUseCurves->setChecked( false );
74-
cbUseCurves->setHidden( true );
75-
#endif
76-
7772
leDrawing->setReadOnly( true );
7873
pbImportDrawing->setHidden( true );
7974
lblMessage->setHidden( true );

‎src/app/dwg/qgsdwgimporter.cpp‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,30 +140,26 @@ void QgsDwgImporter::startTransaction()
140140
{
141141
Q_ASSERT( mDs );
142142

143-
#if defined(GDAL_COMPUTE_VERSION) && GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,0,0)
144143
mInTransaction = GDALDatasetStartTransaction( mDs, 0 ) == OGRERR_NONE;
145144
if ( !mInTransaction )
146145
{
147146
LOG( QObject::tr( "Could not start transaction\nDatabase:%1\nError:%2" )
148147
.arg( mDatabase )
149148
.arg( QString::fromUtf8( CPLGetLastErrorMsg() ) ) );
150149
}
151-
#endif
152150
}
153151

154152
void QgsDwgImporter::commitTransaction()
155153
{
156154
Q_ASSERT( mDs != nullptr );
157155

158-
#if defined(GDAL_COMPUTE_VERSION) && GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,0,0)
159156
if ( mInTransaction && GDALDatasetCommitTransaction( mDs ) != OGRERR_NONE )
160157
{
161158
LOG( QObject::tr( "Could not commit transaction\nDatabase:%1\nError:%2" )
162159
.arg( mDatabase )
163160
.arg( QString::fromUtf8( CPLGetLastErrorMsg() ) ) );
164161
}
165162
mInTransaction = false;
166-
#endif
167163
}
168164

169165
QgsDwgImporter::~QgsDwgImporter()
@@ -186,13 +182,8 @@ bool QgsDwgImporter::import( const QString &drawing, QString &error, bool doExpa
186182
OGRwkbGeometryType lineGeomType, hatchGeomType;
187183
if ( useCurves )
188184
{
189-
#if !defined(GDAL_COMPUTE_VERSION) || GDAL_VERSION_NUM < GDAL_COMPUTE_VERSION(2,0,0)
190-
error = QObject::tr( "Curves only supported with GDAL2" );
191-
return false;
192-
#else
193185
lineGeomType = wkbCompoundCurveZ;
194186
hatchGeomType = wkbCurvePolygonZ;
195-
#endif
196187
}
197188
else
198189
{

‎src/app/ogr/qgsnewogrconnection.cpp‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@
2626
#include <ogr_api.h>
2727
#include <cpl_error.h>
2828

29-
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
30-
#define TO8F(x) (x).toUtf8().constData()
31-
#else
32-
#define TO8F(x) QFile::encodeName( x ).constData()
33-
#endif
34-
3529
QgsNewOgrConnection::QgsNewOgrConnection( QWidget *parent, const QString& connType, const QString& connName, Qt::WindowFlags fl )
3630
: QDialog( parent, fl )
3731
, mOriginalConnName( connName )
@@ -89,7 +83,7 @@ void QgsNewOgrConnection::testConnection()
8983
OGRDataSourceH poDS;
9084
OGRSFDriverH pahDriver;
9185
CPLErrorReset();
92-
poDS = OGROpen( TO8F( uri ), false, &pahDriver );
86+
poDS = OGROpen( uri.toUtf8().constData(), false, &pahDriver );
9387
if ( !poDS )
9488
{
9589
QMessageBox::information( this, tr( "Test connection" ), tr( "Connection failed - Check settings and try again.\n\nExtended error information:\n%1" ).arg( QString::fromUtf8( CPLGetLastErrorMsg() ) ) );

‎src/app/qgisapp.cpp‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,6 @@
266266
#include <gdal_version.h>
267267
#include <proj_api.h>
268268

269-
#if defined(GDAL_COMPUTE_VERSION) && GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(1,11,0)
270-
#define SUPPORT_GEOPACKAGE
271-
#endif
272-
273269
//
274270
// Other includes
275271
//
@@ -1964,10 +1960,6 @@ void QgisApp::createMenus()
19641960
*/
19651961

19661962
// Layer menu
1967-
#ifndef SUPPORT_GEOPACKAGE
1968-
mProjectMenu->removeAction( mActionDwgImport );
1969-
mNewLayerMenu->removeAction( mActionNewGeoPackageLayer );
1970-
#endif
19711963

19721964
// Panel and Toolbar Submenus
19731965
mPanelMenu = new QMenu( tr( "Panels" ), this );
@@ -2241,9 +2233,7 @@ void QgisApp::createToolBars()
22412233
bt->setPopupMode( QToolButton::MenuButtonPopup );
22422234
bt->addAction( mActionNewVectorLayer );
22432235
bt->addAction( mActionNewSpatiaLiteLayer );
2244-
#ifdef SUPPORT_GEOPACKAGE
22452236
bt->addAction( mActionNewGeoPackageLayer );
2246-
#endif
22472237
bt->addAction( mActionNewMemoryLayer );
22482238

22492239
QAction* defNewLayerAction = mActionNewVectorLayer;
@@ -2258,11 +2248,9 @@ void QgisApp::createToolBars()
22582248
case 2:
22592249
defNewLayerAction = mActionNewMemoryLayer;
22602250
break;
2261-
#ifdef SUPPORT_GEOPACKAGE
22622251
case 3:
22632252
defNewLayerAction = mActionNewGeoPackageLayer;
22642253
break;
2265-
#endif
22662254
}
22672255
bt->setDefaultAction( defNewLayerAction );
22682256
QAction* newLayerAction = mLayerToolBar->addWidget( bt );

0 commit comments

Comments
 (0)